0
点赞
收藏
分享

微信扫一扫

根据移动还有移动角度来发射武器

杏花疏影1 2022-02-23 阅读 10

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);

       }

   }

}

举报

相关推荐

0 条评论