Пример #1
0
 void Update()
 {
     // enables or disables mouse lock and visibility also pauses game if mouse is visible
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         if (Cursor.visible == true)
         {
             Cursor.lockState = CursorLockMode.Locked;
             Cursor.visible   = false;
             Time.timeScale   = 1f;
             settingsPopUp.Close();
         }
         else
         {
             Cursor.lockState = CursorLockMode.None;
             Cursor.visible   = true;
             Time.timeScale   = 0f;
             settingsPopUp.Open();
         }
     }
     // enables shooing only if game isnt paused
     if (Time.timeScale != 0)
     {
         if ((Input.GetKeyDown(KeyCode.RightControl)) && (!EventSystem.current.IsPointerOverGameObject()))
         {
             // this creates a vector with the coridnates of the rays origin
             Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
             muzzleFlash.Play();
             gunShot.Play();
             // creates ray object with origin cordinates
             Ray ray = _camera.ScreenPointToRay(point);
             // pases the ray and a new object with type RaycastHit
             if (Physics.Raycast(ray, out RaycastHit hit))
             {
                 // this retrieves the object the ray hit
                 GameObject     hitObject  = hit.transform.gameObject;
                 ReactiveTarget target     = hitObject.GetComponent <ReactiveTarget>();
                 GameObject     enemy      = hit.transform.gameObject;
                 WanderingAI    lifeStatus = enemy.GetComponent <WanderingAI>();
                 // this checks if the target is a person though the get component method and if it is
                 // it returns a hit and if not it creates a sphere in the debug console.
                 // get component returns null if the component isnt there.
                 if ((target != null) && (lifeStatus.getAlive()))
                 {
                     target.ReactToHit();
                     Messenger.Broadcast(GameEvent.ENEMY_HIT);
                 }
                 else
                 {
                     // starts the coroutine kicking control to it
                     StartCoroutine(SphereIndicator(hit.point));
                 }
             }
         }
     }
 }
Пример #2
0
 // нанесение урона врагу
 public void ReactToHit()
 {
     if (!_enemy.getAlive())
     {
         return;
     }
     _enemy.SetAlive(false);
     // компонент нужен для падения
     gameObject.AddComponent <Rigidbody>();
     StartCoroutine(Die());
 }