예제 #1
0
    private void OnTriggerEnter(Collider other)
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            Rigidbody targetRigidbody = colliders [i].GetComponent <Rigidbody> ();

            if (!targetRigidbody)
            {
                continue;
            }
            targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);
            TankLife targetHealth = targetRigidbody.GetComponent <TankLife> ();
            if (!targetHealth)
            {
                continue;
            }
            float damage = CalculateDamage(targetRigidbody.position);

            targetHealth.TakeDamage(damage);
        }

        m_ExplosionParticles.transform.parent = null;
        m_ExplosionParticles.Play();
        m_ExplosionAudio.Play();
        var main = m_ExplosionParticles.main;

        Destroy(m_ExplosionParticles.gameObject, main.duration);
        Destroy(gameObject);
    }
예제 #2
0
    void Awake()
    {
        tf     = GetComponent <Transform>();
        move   = GetComponent <TankMove>();
        attack = GetComponent <TankAttack>();
        life   = GetComponent <TankLife>();

        //Removed Reverse Speed and just divided the speed
        //by 3 when moving backwards, I would have to completely
        //change Move and IController to keep and use the reverse
        //variable.
        tankForwardSpeed = 5;
        tankRotateSpeed  = 100;

        tankMaxLife     = 100;
        tankCurrentLife = 100;
        tankArmor       = 5;

        tankGunDamage         = 6;
        tankGunAmmoMax        = 100;
        tankGunAmmoCurrent    = 100;
        tankCannonDamage      = 40;
        tankCannonAmmoMax     = 10;
        tankCannonAmmoCurrent = 10;

        tankCannonFireR = 3;

        lives     = 3;
        tankScore = 0;
    }
예제 #3
0
 private void Awake()
 {
     tankData     = GetComponent <TankData>();
     tankAttack   = GetComponent <TankAttack>();
     tankLife     = GetComponent <TankLife>();
     tankMove     = GetComponent <TankMove>();
     currentState = AIStates.Camp;
 }
예제 #4
0
 void Awake()
 {
     //'this.gameObject.' is not required, but it leaves
     //very little to the imagination as to what the
     //reference is for.  Here we attach those variables
     //to these scripts so that they will interact.
     tf     = this.gameObject.GetComponent <Transform>();
     move   = this.gameObject.GetComponent <TankMove>();
     attack = this.gameObject.GetComponent <TankAttack>();
     life   = this.gameObject.GetComponent <TankLife>();
 }
예제 #5
0
    private int wayPointIndex; // A counter for the way point array.

    #endregion Fields

    #region Methods

    void Awake()
    {
        // Setting up the references.
        enemySight = GetComponent<EnemySight>();
        nav = GetComponent<NavMeshAgent>();
        player = player.transform;
        playerHealth = player.GetComponent<TankLife>();
        lastPlayerSighting = GetComponent<LastPlayerSighting> ();
        enemyHealth = GetComponent<TankLife> ();
        //canonDirection = GetComponent<rotateEnemyCanon> ();
        //lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<LastPlayerSighting>(); //?
    }
예제 #6
0
    private Vector3 previousSighting; // Where the player was sighted last frame.

    #endregion Fields

    #region Methods

    void Awake()
    {
        // Setting up the references.
        nav = GetComponent<NavMeshAgent>();
        col = GetComponent<SphereCollider>();

        lastPlayerSighting = GetComponent<LastPlayerSighting>();

        playerHealth = player.GetComponent<TankLife>();
        enemyHealth = GetComponent<TankLife> ();

        // Set the personal sighting and the previous sighting to the reset position.
        personalLastSighting = lastPlayerSighting.resetPosition;
        previousSighting = lastPlayerSighting.resetPosition;
        doubleRadius = col.radius * 2f;
    }
예제 #7
0
    void Explode()
    {
        GameObject explosion = Instantiate(shellExplosion, transform.position, transform.rotation) as GameObject;

        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);

        foreach (var c in colliders)
        {
            //Debug.Log("Collider found in explosion radius: " + c.gameObject.name);
            if (c.gameObject.tag == "Player" || c.gameObject.tag == "Enemy")
            {
                Rigidbody rb = c.GetComponent <Rigidbody>();
                rb.AddExplosionForce(explosionForce, transform.position, explosionRadius);
                float damage = damageCalc(rb.position);
                Debug.Log("damage done: " + damage.ToString());
                TankLife hp = c.gameObject.GetComponent <TankLife>();
                hp.TakeDamage(damage);
            }
        }

        Destroy(explosion, 1.5f);
    }