private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Enemy")
        {
            Debug.Log(other.gameObject.tag);
            target target1 = other.transform.GetComponent <target>();

            if (target1 != null)
            {
                target1.takedamage(damage);
                if (target1.health <= 0)
                {
                    Destroy(other.gameObject);
                }

                var bullet = GameObject.Instantiate(impacteffect);
                bullet.transform.position = transform.position;
                Destroy(bullet, 2f);
                Destroy(this.gameObject);
            }
            Debug.Log("enemy health: " + target1.health);
        }
        if (other.gameObject.tag == "static_obj")
        {
            Debug.Log(other.gameObject.tag);

            var bullet = GameObject.Instantiate(impacteffect);
            bullet.transform.position = transform.position;
            Destroy(this.gameObject);
            Destroy(bullet, 2f);
        }
    }
示例#2
0
    public void shoot()
    {
        MuzzleFlash.Play();

        RaycastHit hit;

        //Instantiate(muzzle, a.gameObject.transform.position, Quaternion.identity);
        if (Physics.Raycast(fps.transform.position, fps.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);


            target Target = hit.transform.GetComponent <target>();
            if (Target != null)
            {
                Target.takedamage(damage);
            }
            target1 Target1 = hit.transform.GetComponent <target1>();
            if (Target1 != null)
            {
                Target1.takedamage(damage);
            }
            target2 Target2 = hit.transform.GetComponent <target2>();
            if (Target2 != null)
            {
                Target2.takedamage(damage);
            }
            GameObject im = Instantiate(a, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(im, 2f);
        }
    }
示例#3
0
文件: shoot.cs 项目: Saikarthi/Tank
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "enemy")
     {
         speed = 0f;
         ContactPoint c   = collision.contacts[0];
         Quaternion   rot = Quaternion.FromToRotation(Vector3.up, c.normal);
         Vector3      pos = c.point;
         var          vfx = Instantiate(hitpoint, pos, rot);
         Destroy(vfx, 2f);
         Destroy(gameObject);
         if (collision.gameObject.tag == "enemy")
         {
             Target = collision.transform.GetComponent <target>();
         }
         if (Target != null)
         {
             Target.takedamage(damage);
         }
     }
 }