Example #1
0
 private void Update()
 {
     CameraRotation();
     if (sp.IsOpen)
     {
         char[]   delimiterChars = { ',' };
         string   param          = sp.ReadLine();
         string[] words          = param.Split(delimiterChars);
         for (int i = 0; i <= 2; i++)
         {
             if (i == 0)
             {
                 x = float.Parse(words[i]);
             }
             if (i == 2)
             {
                 y = float.Parse(words[i]);
             }
         }
         if (int.Parse(words[3]) == 1)
         {
             Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
             Ray        ray   = _camera.ScreenPointToRay(point);
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit))//hit就是被擊中的目標
             {
                 // Debug.Log(point);
                 //獲取打到的物體
                 GameObject hitobj = hit.transform.gameObject;
                 yDie       RT     = hitobj.GetComponent <yDie>();
                 if (RT != null)
                 {
                     RT.Reacttohit();//呼叫敵人的被擊反饋
                 }
                 else
                 {
                     StartCoroutine(F(hit.point));//用協程造子彈,因為要編寫子彈要1s後消失的效果
                 }
             }
         }
         else
         {
         }
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        //響應左鍵
        if (Input.GetMouseButton(0) == true)
        {
            Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
            Ray        ray   = _camera.ScreenPointToRay(point);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))//hit就是被擊中的目標
            {
                // Debug.Log(point);
                //獲取打到的物體
                GameObject hitobj = hit.transform.gameObject;
                yDie       RT     = hitobj.GetComponent <yDie>();
                if (RT != null)
                {
                    RT.Reacttohit();//呼叫敵人的被擊反饋
                    count--;
                }
                else
                {
                    StartCoroutine(F(hit.point));//用協程造子彈,因為要編寫子彈要1s後消失的效果
                }
                Debug.Log(count);
            }
            fire.Play();
        }
        if (count == 0 && windowSwitch == 0)
        {
            windowSwitch     = 1;
            alpha            = 0; // Init Window Alpha Color
            Time.timeScale   = 0;
            Cursor.lockState = CursorLockMode.None;
            count++;
        }

        /*else if (count == 0 && windowSwitch == 1)
         * {
         *  windowSwitch = 0;
         *  Time.timeScale = 1;
         *  Cursor.lockState = CursorLockMode.Locked;
         *
         * }*/
    }