示例#1
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.tag == "Player")
     {
         a = collision.gameObject.GetComponent <FPSController>();
         a.Damage(this.tag);
     }
 }
示例#2
0
    private void OnTriggerEnter(Collider other)
    {
        if (dead)
        {
            return;
        }

        if (hitType == ProjectileHit.Enemy)
        {
            if (other.gameObject.layer.Equals(LayerMask.NameToLayer("Enemy")) || other.GetComponent <EnemyController>())
            {
                EnemyController controller = other.GetComponent <EnemyController>();
                controller.Damage(damage);
                Destroy(gameObject);
                dead = true;
            }
            else if (!other.gameObject.layer.Equals(LayerMask.NameToLayer("Player")) && !other.gameObject.layer.Equals(LayerMask.NameToLayer("First Person")) && !other.gameObject.layer.Equals(LayerMask.NameToLayer("Tool")))
            {
                velocity            = Vector3.zero;
                transform.position += transform.forward * 0.1f;
            }
        }
        else
        {
            if (other.gameObject.layer.Equals(LayerMask.NameToLayer("Player")) || other.GetComponent <FPSController>())
            {
                FPSController controller = other.GetComponent <FPSController>();
                controller.Damage(damage);
                Destroy(gameObject);
                dead = true;
            }
            else if (!other.gameObject.layer.Equals(LayerMask.NameToLayer("First Person")) && !other.gameObject.layer.Equals(LayerMask.NameToLayer("Enemy")) && !other.gameObject.layer.Equals(LayerMask.NameToLayer("Tool")))
            {
                velocity            = Vector3.zero;
                transform.position += transform.forward * 0.1f;
            }
        }
    }