U3D FistWeek Summary

    xiaoxiao2021-12-14  18

    1、Project Tank

    ***Bullet Flying Script

    /* void Start ()     {         transform.Rotate(Vector3.forward, 90);         transform.forward = GameObject.Find("Target").transform.position - transform.position;     }     float timer = 0;     // Update is called once per frame     void Update ()     {         timer+= Time.deltaTime;         //让子弹发生变换         transform.position += transform.forward * 10 * Time.deltaTime;         //transform.position += (GameObject.Find("Target").transform.position - transform.position) * 0.05f;         if ((transform.position - GameObject.Find("Target").transform.position).magnitude < 0.1)         {             Destroy(gameObject);         }     }

    */

    ***Bullet Creater Script

    /*

    public GameObject bullet;     // Use this for initialization     void Start ()     {     }     // Update is called once per frame     float timer;     void Update ()     {         timer += Time.deltaTime;         if (timer >= 1)         {             timer = 0;             Instantiate(bullet, transform.position, Quaternion.identity);         }     }

    */

    ***Make Gun Lookat The Target

    /*     void Start ()     {         transform.Rotate(Vector3.back);     }               void Update ()     {         Quaternion qua = Quaternion.LookRotation(GameObject.Find("Cube").transform.position - transform.position);         transform.rotation = qua;     }

    */

    ***WASD Control Move of Tank

    /*

    void TankMove()     {         float hA=Input.GetAxis("Horizontal");         float vA = Input.GetAxis("Vertical");         if (vA >= 0)         {             transform.Rotate(Vector3.left * hA * 30 * Time.deltaTime);         }         else         {             transform.Rotate(Vector3.right * hA * 30 * Time.deltaTime);         }         transform.Translate(Vector3.forward * vA * 0.5f);     }

    */

    ***Using Lerp

    //通过VECTOR线性差值移动物体         //transform.position = Vector3.Lerp(transform.position, GameObject.Find("Sphere").transform.position, 0.5f * Time.deltaTime);         //if (Vector3.Distance(transform.position, GameObject.Find("Sphere").transform.position) < 0.01f)         //{         //    transform.position = GameObject.Find("Sphere").transform.position;         //}

    ***Move Cube with Mouse Drag

    /*

        void OnMouseEnter()     {         Debug.Log("in!");     }     Vector3 offset;     void OnMouseDown()     {         //开始拖拽         Debug.Log("down!");         Vector3 mousev = Input.mousePosition;         //将鼠标坐标转换为世界坐标         Vector3 screenSpace = Camera.main.WorldToScreenPoint(transform.position);         Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(new Vector3(mousev.x, mousev.y,screenSpace.z));         offset = transform.position - mouseWorld;     }     void OnMouseDrag()     {         //鼠标拖拽时调用         Debug.Log("drag!");         //mx = Input.GetAxis("Mouse X");         //my = Input.GetAxis("Mouse Y");         //transform.position += Vector3.right * mx;         //transform.position += Vector3.up * my;         Vector3 mousev = Input.mousePosition;         //将鼠标坐标转换为世界坐标         Vector3 screenSpace = Camera.main.WorldToScreenPoint(transform.position);         Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(new Vector3(mousev.x, mousev.y, screenSpace.z));         transform.position = mouseWorld + offset;     }

    */

    ***Mouse DoubleClicks

    /*

     float timer;     bool intodouble1 = false;     bool intodouble2 = false;     float time1;     void Start ()     {          }     void Update ()     {         timer += Time.deltaTime;         if (Input.GetMouseButtonDown(0))         {             intodouble1 = true;             if (intodouble1 && (intodouble2 == false))             {                 time1 = timer;                 intodouble2 = true;             }             else             {                 if (intodouble1 && intodouble2)                 {                     if (timer - time1 < 0.6)                     {                         Debug.Log("DoubleClick");                     }                     intodouble1 = false;                     intodouble2 = false;                 }             }         }         if (timer - time1 > 0.6)         {             intodouble1 = false;             intodouble2 = false;         }

    */

    ***Camera Move

    /// <summary>     /// 摄像机移动方法(防止颠倒改良版)     /// </summary>     void CameraMove()     {         vA = Input.GetAxis("Vertical");         hA = Input.GetAxis("Horizontal");         mX = Input.GetAxis("Mouse X");         mY = Input.GetAxis("Mouse Y");

            transform.position += transform.forward * vA * 0.5f;         transform.position += transform.right * hA * 0.5f;         transform.Rotate(Vector3.up, mX);         transform.Rotate(Vector3.left, mY * 0.5f);

            Vector3 oldrotation = transform.rotation.eulerAngles;         oldrotation.z = 0;         transform.rotation = Quaternion.Euler(oldrotation);         transform.position=new Vector3(transform.position.x, 1.5f, transform.position.z);     }

    The scene of Delegate in U3D04 is the strandrard mothd to use event and delegate.

    Edit by Suxny

    If Reproduced,,please indicate the source.

    转载请注明原文地址: https://ju.6miu.com/read-969232.html

    最新回复(0)