Пример #1
0
    void OnCollisionEnter(Collision collision)
    {
        Instantiate(explosion, transform.position, transform.rotation);
        GameObject  sound  = GameObject.Find("SoundManager");
        AudioSource source = sound.GetComponent <AudioSource>();

        source.PlayOneShot(clip, 1f);
        this.gameObject.SetActive(false);
        Debug.Log(collision.gameObject.tag);

        if (collision.gameObject.CompareTag("Player"))
        {
            DamageOverNetwork dmgHandler = collision.gameObject.GetComponent <DamageOverNetwork>();
            NetworkIdentity   id         = collision.gameObject.GetComponent <NetworkIdentity>();
            string            hitBoxName = collision.GetContact(0).otherCollider.gameObject.name;
            Debug.Log(hitBoxName);
            dmgHandler.DamagePlayer(damage, hitBoxName, id);
        }

        if (collision.gameObject.CompareTag("Building"))
        {
            collision.gameObject.GetComponent <IDamagable>().Damage(damage);
            SwapToBroken toSwitch = collision.gameObject.GetComponentInParent <SwapToBroken>();
            if (toSwitch != null)
            {
                toSwitch.swapToBroken();
            }
            Vector3    explosionPos = transform.position;
            Collider[] colliders    = Physics.OverlapSphere(explosionPos, 8f);
            foreach (Collider hit in colliders)
            {
                Rigidbody rb = hit.GetComponent <Rigidbody>();

                if (rb != null)
                {
                    rb.AddExplosionForce(1000, explosionPos, 1.8f);
                }
            }
        }
    }
Пример #2
0
 void Start()
 {
     dmgOverNet = transform.root.GetComponent <DamageOverNetwork>();
 }