示例#1
0
    private void OnTriggerEnter(Collider other)
    {
        //nblockHealth targetnBlockHealth = other.GetComponent<nblockHealth>();
        //targetnBlockHealth.TakeDamage(m_Damage);
        //Destroy(other.gameObject);

        //get target layer
        int blockMask  = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("NormalBlockLayer"), 2f));
        int playerMask = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("PlayerLayer"), 2f));
        int enemyMask  = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("EnemyLayer"), 2f));
        int EcubeMask  = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("EnergyCubeLayer"), 2f));


        if (other.gameObject.layer == blockMask)
        {
            nblockHealth blockHealth = other.gameObject.GetComponent <nblockHealth>();
            blockHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.layer == enemyMask)
        {
            eTankHealth etkHealth = other.gameObject.GetComponent <eTankHealth>();
            etkHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.CompareTag("Player"))
        {
            tankHealth tkHealth = other.gameObject.GetComponent <tankHealth>();
            tkHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.layer == EcubeMask)
        {
            nblockHealth blockHealth = other.gameObject.GetComponent <nblockHealth>();
            blockHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.layer == 2 && other.gameObject.CompareTag("Walls"))
        {
            Destroy(gameObject);
        }
    }
示例#2
0
    void OnCollisionEnter(Collision collision)       //碰撞發生時呼叫
    //碰撞後產生爆炸

    {
        Instantiate(effect, transform.position, transform.rotation);
        if (collision.gameObject.tag == "enemy" || collision.gameObject.tag == "Player")
        {
            tankHealth targetHealth = collision.gameObject.GetComponent <tankHealth>();
            if (!targetHealth)
            {
                return;
            }
            float vol = Random.Range(volLowRange, volHighRange);
            tankSource.PlayOneShot(hitsound[Random.Range(0, hitsound.Length)], vol);
            float damage = collision.gameObject.tag == "Player"? 10f: 5f;
            damage += (gameObject.tag == "bullet"? 0f: 5f);
            targetHealth.TakeDamage(damage);
        }
        Destroy(gameObject);//刪除砲彈
        // }
    }
示例#3
0
    private void OnCollisionEnter(Collision other)
    {
        // find the rigidbody of the collision object
        Rigidbody targetRigidbody = other.gameObject.GetComponent <Rigidbody>();

        if (targetRigidbody.tag == "Enemy")
        {
            // only tanks will have rigidbody scripts
            if (targetRigidbody != null)
            {
                // Add an explosion force
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                //find the TankHealth script associated with the rigidbody
                tankHealth targetHealth = targetRigidbody.GetComponent <tankHealth>();

                if (targetHealth != null)
                {
                    // calculate the amount of damge the target should take
                    // based on it's distance from the shell.
                    float damage = CalculateDamage(targetRigidbody.position);

                    // Deal this damage to the tank
                    targetHealth.TakeDamage(damage);
                }
            }

            // Unparent the particles from the shell
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system
            m_ExplosionParticles.Play();

            // Once the particles have finished, destroy the gameObject they are on
            Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration);

            // Destroy the shell
            Destroy(gameObject);
        }
    }
    void OnDestroy()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, mExplosionRadius, mTankMask);
        for (int i = 0; i < colliders.Length; i++)
        {
            Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
            if (!targetRigidbody)
            {
                continue;
            }
            targetRigidbody.AddExplosionForce(mExplosionForce, transform.position, mExplosionRadius);

            tankHealth targetHealth = targetRigidbody.GetComponent <tankHealth>();
            if (!targetHealth)
            {
                continue;
            }
            float damage = 10f;

            targetHealth.TakeDamage(damage);
        }
    }
    void Update()
    {
        if (Time.time - effectTime > 2)
        {
            effectTime = Time.time;
            Destroy(mMineEffectInst);
            mMineEffectInst = Instantiate(mMineEffect, new Vector3(0f, 0f, 0f), Quaternion.Euler(0f, 0f, 0f)) as GameObject;
            mMineEffectInst.transform.localPosition = new Vector3(0f, 0f, 0f);
            mMineEffectInst.transform.position      = gameObject.transform.position;
            mMineEffectInst.transform.parent        = gameObject.transform;
        }
        if (Time.time - countTime > mCountTime)
        {
            Instantiate(mExplosionEffect, transform.position, transform.rotation);
            Collider[] colliders = Physics.OverlapSphere(transform.position, mExplosionRadius, mTankMask);
            for (int i = 0; i < colliders.Length; i++)
            {
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
                if (!targetRigidbody)
                {
                    continue;
                }
                targetRigidbody.AddExplosionForce(mExplosionForce, transform.position, mExplosionRadius);

                tankHealth targetHealth = targetRigidbody.GetComponent <tankHealth>();
                if (!targetHealth)
                {
                    continue;
                }
                float damage = 5f;

                targetHealth.TakeDamage(damage);
            }

            DestroyObject(gameObject);
        }
    }