Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         sound.Shoot();
         // Get middle of screen
         Vector3    point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
         Ray        ray   = _camera.ScreenPointToRay(point);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             // Debug.Log ("Hit " + hit.point);
             GameObject hitObject = hit.transform.gameObject;
             // You couldn't hit 2 things at once, could you?
             Hittable target = hitObject.GetComponent <Hittable> ();
             if (target != null)
             {
                 Debug.Log("inlficting damage!!!");
                 target.ReactToHit(damage);
             }
             else
             {
                 // StartCoroutine (SphereIndicator (hit.point));
             }
         }
     }
 }
    void OnTriggerEnter(Collider other)
    {
        Hittable hitObject = other.GetComponent <Hittable>();

        if (hitObject != null)
        {
            hitObject.ReactToHit(damage);
        }
    }
Beispiel #3
0
    void OnTriggerEnter(Collider other)
    {
        Hittable hitObject = other.GetComponent <Hittable>();

        if (hitObject != null)
        {
            _monsterInRange = true;
            hitObject.ReactToHit(damage);
        }
        else
        {
            Debug.Log("Hit a wall");
        }
    }