Example #1
0
    // Shoot in the specified direction
    public void Shoot(Vector3 dir)
    {
        System.TimeSpan ts = System.DateTime.Now - lastShootTime;

        if (turretState != TankTurretState.Firing1 && ts.TotalSeconds > tank.prop.shootCoolDown)
        {
            lastShootTime = System.DateTime.Now;

            // Get the delta angle to rotate the turret
            float turretAngle = Vector3.Angle(turretTransform.forward, dir);

            accumTimeTurret = 0.0f;
            turretState     = TankTurretState.Firing1;

            missile = missileManager.GetItem();
            missile.transform.position = spawnPointTransform.position;
            missile.transform.forward  = cannonTransform.forward;
            missile.SetActive(true);
            missile.GetComponent <Missile>().SetOnMissileHit(OnMissileHit);

            tank.AI.OnShoot();
        }
        else
        {
            Debug.LogFormat("TankTurret@Shoot. Cannot shoot. Last shoot is still too recent. State: {0}", turretState);
        }
    }
Example #2
0
    // Direct hit
    public void DirectHit(float missileHitDamage, Vector3 hitPosition)
    {
        GameObject explosionItem = explosionManager.GetItem();

        explosionItem.transform.position = hitPosition;
        explosionItem.SetActive(true);
        explosionItem.GetComponent <ParticleSystem>().Play();
        explosionManager.RecycleItemAfterSecs(explosionItem, 3.0f);

        SoundManager.Instance.PlaySound(SndId.SND_EXPLOSION_OBSTACLE);

        prop.health = Mathf.Clamp(prop.health - missileHitDamage, 0.0f, float.MaxValue);

        if (prop.health == 0.0f)
        {
            GameObject flameItem = flameManager.GetItem();
            flameItem.transform.position = new Vector3(transform.position.x, 1.7f, transform.position.z);
            flameItem.SetActive(true);
            flameItem.GetComponent <ParticleSystem>().Play();
            flameManager.RecycleItemAfterSecs(flameItem, 3.0f);

            // Destroy the object in 3 seconds
            destroyTimer = 3.0f;
        }
    }
Example #3
0
    // Unity Update Method
    void Update()
    {
        hull.Update();
        turret.Update();

        if (destroyTimer > 0.0f)
        {
            destroyTimer -= Time.deltaTime;

            if (destroyTimer <= 0.0f)
            {
                GameObject detonationItem = detonationManager.GetItem();
                detonationItem.transform.position = new Vector3(transform.position.x, 1.7f, transform.position.z);
                detonationItem.SetActive(true);
                detonationManager.RecycleItemAfterSecs(detonationItem, 3.0f);

                UnityEngine.Object.Destroy(this.gameObject);
            }
        }
    }