using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class attack : MonoBehaviour
{
private float v;
private float h;
private Vector3 dir;
public Transform attack0;
public GameObject weapons;
private float fireRate = 0.5f;
private float nextFire;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
dir = new Vector3(h, v, 0);
if (h > 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, -90);
}
if (h < 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, 90);
}
if (v > 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, 0);
}
if (v < 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, 180);
}
if (h > 0 && v > 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, -45);
}
if (h < 0 && v > 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, 45);
}
if (h > 0 && v < 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, -135);
}
if (h < 0 && v < 0)
{
attack0.transform.localEulerAngles = new Vector3(0, 0, 135);
}
if (Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(weapons, attack0.position, attack0.rotation);
}
}
}