Beispiel #1
0
        /// <summary>
        /// Calculate damage to be taken by the Player,
        /// triggers score increase and respawn workflow on death.
        /// </summary>
        public void TakeDamage(BulletSP bullet)
        {
            int totalDamage = bullet.damage - tankArmor;

            //substract health by damage
            health -= totalDamage;
            OnHealthChange(health);

            //bullet killed the player
            if (health <= 0)
            {
                //the game is already over so don't do anything
                if (GameManagerSinglePlayer.GetInstance().gameOver)
                {
                    return;
                }

                //get killer and increase score for that team
                SinglePlayer other = bullet.owner.GetComponent <SinglePlayer>();
                GameManagerSinglePlayer.GetInstance().score[other.teamIndex]++;
                GameManagerSinglePlayer.GetInstance().ui.OnTeamScoreChanged(other.teamIndex);
                //the maximum score has been reached now
                if (GameManagerSinglePlayer.GetInstance().IsGameOver())
                {
                    //tell client the winning team
                    GameOver(other.teamIndex);
                    return;
                }

                //the game is not over yet, reset runtime values
                health = maxHealth;
                OnHealthChange(health);
                Respawn();
            }
        }
Beispiel #2
0
        //shoots a bullet in the direction passed in
        //we do not rely on the current turret rotation here, because we send the direction
        //along with the shot request to the server to absolutely ensure a synced shot position
        protected void Shoot(Vector2 direction = default(Vector2))
        {
            //if shot delay is over
            if (Time.time > nextFire)
            {
                //set next shot timestamp
                nextFire = Time.time + fireRate;

                //spawn bullet using pooling, locally
                GameObject obj = PoolManager.Spawn(bullet, shotPos.position, turret.rotation);
                BulletSP   blt = obj.GetComponent <BulletSP>();
                blt.owner = gameObject;

                if (shotFX)
                {
                    PoolManager.Spawn(shotFX, shotPos.position, Quaternion.identity);
                }
                if (shotClip)
                {
                    AudioManager.Play3D(shotClip, shotPos.position, 0.1f);
                }
            }
        }