コード例 #1
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         enemyHealth.enemyDeath();
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        Vector3 mouseRay = new Vector3(Input.mousePosition.x, 2f, 0f);


        RaycastHit [] hits;

        Ray ray = Camera.main.ScreenPointToRay(mouseRay);


        //Vector3 rot;



        ray.origin = transform.position;

        ray.direction = mouseRay;
        int face = 1;

        if (mouseRay.x > player.transform.position.x && orientation.getOrientation() == -1)
        {
            gunLine.SetPosition(0, ray.origin + ray.direction * -range);
            face = -1;
        }
        else if (mouseRay.x > player.transform.position.x && orientation.getOrientation() == 1)
        {
            gunLine.SetPosition(0, ray.origin + ray.direction * range);
            face = 1;
        }

        hits = Physics.RaycastAll(ray.origin, ray.direction * face, range);
        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].collider.tag == "Enemy")
            {
                Debug.Log("shoot it");
                enemyHealthController enemyHealth = hits[i].collider.GetComponent <enemyHealthController> ();


                Debug.Log("hit enemy");
                enemyHealth.enemyDeath();
            }
        }
    }