Beispiel #1
0
        protected override void RpcRespawn()
        {
//            StartCoroutine(Respawn());

            isDead = true;
            inRange.Clear();
            agent.Stop();

            if (explosionFX)
            {
                //spawn death particles locally using pooling and colorize them in the player's team color
                GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                if (pColor)
                {
                    pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color);
                }
            }

            //play sound clip on player death
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            FindObjectOfType <BotSpawner>().Despawn(this.gameObject);

            targetPoint        = GameManager.GetInstance().GetSpawnPosition(GetView().GetTeam());
            transform.position = targetPoint;
            agent.Warp(targetPoint);
            agent.Resume();
            isDead = false;
        }
Beispiel #2
0
        protected void SpawnBullet(int newRotation, bool DoubleDmg)
        {
            //spawn bullet using pooling, locally
            GameObject obj = PoolManager.Spawn(bullet, shotPos.position, Quaternion.Euler(0, newRotation, 0));
            Bullet     blt = obj.GetComponent <Bullet>();

            blt.owner = gameObject;

            Debug.Log("Double Damage is: " + DoubleDmg);
            Debug.LogError("Double Damage is: " + DoubleDmg);
            MeshRenderer meshRenderer = blt.GetComponent <MeshRenderer>();

            Material[] materials = meshRenderer.materials;
            if (DoubleDmg)
            {
                materials[0] = blt.DoubleMat;
            }
            else
            {
                materials[0] = blt.defaultMat;
            }

            meshRenderer.materials = materials;

            blt.DoubleDamage = DoubleDmg;
        }
Beispiel #3
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;



                // Create the Bullet from the Bullet Prefab //Working
                //var blt = (GameObject)Instantiate(bullet, shotPos.position, turret.rotation);
                //Bullet bltSpawned = blt.GetComponent<Bullet>();
                //bltSpawned.owner = gameObject;


                CmdShootBullet();



                if (shotFX)
                {
                    PoolManager.Spawn(shotFX, shotPos.position, Quaternion.identity);
                }
                if (shotClip)
                {
                    AudioManager.Play3D(shotClip, shotPos.position, 0.1f);
                }
            }
        }
Beispiel #4
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;

                //create bullet from prefab
                GameObject bullet = (GameObject)Instantiate(bulletPrefab, shotPos.position, turret.rotation);

                //add velocity to bullet
                bullet.GetComponent <Rigidbody>().velocity = bullet.transform.forward * 6.0f;

                //bulletSpawn bullet on client
                NetworkServer.Spawn(bullet);

                //destory bullet after 2 sec
                Destroy(bullet, 2);

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

                if (shotFX)
                {
                    PoolManager.Spawn(shotFX, shotPos.position, Quaternion.identity);
                }
                if (shotClip)
                {
                    AudioManager.Play3D(shotClip, shotPos.position, 0.1f);
                }
            }
        }
Beispiel #5
0
        IEnumerator Stun(float time)
        {
            agent.Stop();
//            EffectStun.SetActive(true);

//            HitStun.SetActive(true);
            if (EffectStun)
            {
                PoolManager.Spawn(EffectStun, transform.position, Quaternion.identity);
            }

            if (HitStun)
            {
                PoolManager.Spawn(HitStun, transform.position, Quaternion.identity);
            }

            CheckStatestun  = false;
            CheckStatestun2 = true;

            yield return(new WaitForSeconds(countStun));

            CheckStatestun2 = false;

            agent.Resume();

            // Pop StunState
            fsm.PopState();
        }
Beispiel #6
0
        public void Instantiate()
        {
            //sanity check in case there already is an object active
            if (obj != null)
            {
                return;
            }

            obj = PoolManager.Spawn(prefab, transform.position, transform.rotation);
            //set the reference on the instantiated object for cross-referencing
            Collectible colItem = obj.GetComponent <Collectible>();

            if (colItem != null)
            {
                //set cross-reference
                colItem.spawner = this;
                //set internal item type automatically
                if (colItem is CollectibleTeam)
                {
                    colType = CollectionType.Pickup;
                }
                else
                {
                    colType = CollectionType.Use;
                }
            }
        }
Beispiel #7
0
        protected void CmdShoot(short[] position, short angle)
        {
            //get current bullet type
            int currentBullet = GetView().GetBullet();

            //calculate center between shot position sent and current server position (factor 0.6f = 40% client, 60% server)
            //this is done to compensate network lag and smoothing it out between both client/server positions
            Vector3    shotCenter = Vector3.Lerp(shotPos.position, new Vector3(position[0] / 10f, shotPos.position.y, position[1] / 10f), 0.6f);
            Quaternion syncedRot  = turret.rotation = Quaternion.Euler(0, angle, 0);

            //spawn bullet using pooling
            GameObject obj = PoolManager.Spawn(bullets[currentBullet], shotCenter, syncedRot);

            obj.GetComponent <Bullet>().owner = gameObject;

            //check for current ammunition
            //let the server decrease special ammunition, if present
            if (PhotonNetwork.IsMasterClient && currentBullet != 0)
            {
                //if ran out of ammo: reset bullet automatically
                GetView().DecreaseAmmo(1);
            }

            //send event to all clients for spawning effects
            if (shotFX || shotClip)
            {
                RpcOnShot();
            }
        }
Beispiel #8
0
        //set despawn effects and reset variables
        void OnDespawn()
        {
            //create clips and particles on despawn
            if (explosionFX)
            {
                PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
            }
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            //reset modified variables to the initial state
            myRigidbody.velocity        = Vector3.zero;
            myRigidbody.angularVelocity = Vector3.zero;
            bounce = maxBounce;

            //skip for non-hosts
            if (!isServer)
            {
                return;
            }
            //server despawned this instance, despawn it for the network too
            NetworkServer.UnSpawn(gameObject);
        }
Beispiel #9
0
        //check what was hit on collisions
        void OnTriggerEnter(Collider col)
        {
            //cache corresponding gameobject that was hit
            GameObject obj = col.gameObject;
            //try to get a player component out of the collided gameobject
            Player player = obj.GetComponent <Player> ();

            //we actually hit a player
            //do further checks
            if (player != null)
            {
                //ignore ourselves & disable friendly fire (same team index)
                if (player.gameObject == owner || player.gameObject == null)
                {
                    return;
                }
                //else if (player.teamIndex == owner.GetComponent<Player>().teamIndex)
                //    return;

                //create clips and particles on hit
                if (hitFX)
                {
                    PoolManager.Spawn(hitFX, transform.position, Quaternion.identity);
                }
                if (hitClip)
                {
                    AudioManager.Play3D(hitClip, transform.position);
                }

                //on the player that was hit, set the killing player to the owner of this bullet
                //maybe this owner really killed the player, but that check is done in the Player script
                player.killedBy = owner;
            }

            if (isServer)
            {
                PoolManager.Despawn(gameObject, 0f);
            }


            //apply bullet damage to the collided player
            if (player)
            {
                player.TakeDamage(this);
            }


            //var hit = col.gameObject;
            //var health = hit.GetComponent<Player>();
            //if (health != null)
            //{
            //    health.TakeDamage(this);
            //}
            //despawn gameobject

            //Destroy(gameObject);

            //PoolManager.Despawn (gameObject);
        }
Beispiel #10
0
        //the actual respawn routine
        IEnumerator Respawn(short senderId)
        {
            //stop AI updates
            isDead = true;
            inRange.Clear();
            agent.isStopped = true;
            killedBy        = null;

            //find original sender game object (killedBy)
            PhotonView senderView = senderId > 0 ? PhotonView.Find(senderId) : null;

            if (senderView != null && senderView.gameObject != null)
            {
                killedBy = senderView.gameObject;
            }

            //detect whether the current user was responsible for the kill
            //yes, that's my kill: increase local kill counter
            if (killedBy == GameManager.GetInstance().localPlayer.gameObject)
            {
                GameManager.GetInstance().ui.killCounter[0].text = (int.Parse(GameManager.GetInstance().ui.killCounter[0].text) + 1).ToString();
                GameManager.GetInstance().ui.killCounter[0].GetComponent <Animator>().Play("Animation");
            }

            if (explosionFX)
            {
                //spawn death particles locally using pooling and colorize them in the player's team color
                GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                if (pColor)
                {
                    pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color);
                }
            }

            //play sound clip on player death
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            //toggle visibility for all rendering parts (off)
            ToggleComponents(false);
            //wait global respawn delay until reactivation
            yield return(new WaitForSeconds(GameManager.GetInstance().respawnTime));

            //toggle visibility again (on)
            ToggleComponents(true);

            //respawn and continue with pathfinding
            targetPoint        = GameManager.GetInstance().GetSpawnPosition(GetView().GetTeam());
            transform.position = targetPoint;
            agent.Warp(targetPoint);
            agent.isStopped = false;
            isDead          = false;
        }
Beispiel #11
0
        /// <summary>
        /// This is when the respawn delay is over
        /// </summary>
        public virtual void Respawn()
        {
            //toggle visibility for player gameobject (on/off)
            gameObject.SetActive(!gameObject.activeInHierarchy);
            bool isActive = gameObject.activeInHierarchy;

            //the player has been killed
            if (!isActive)
            {
                //detect whether the current user was responsible for the kill
                //yes, that's my kill: increase local kill counter
                if (killedBy == GameManagerSinglePlayer.GetInstance().localPlayer.gameObject)
                {
                    GameManagerSinglePlayer.GetInstance().ui.killCounter[0].text = (int.Parse(GameManagerSinglePlayer.GetInstance().ui.killCounter[0].text) + 1).ToString();
                    GameManagerSinglePlayer.GetInstance().ui.killCounter[0].GetComponent <Animator>().Play("Animation");
                }

                if (explosionFX)
                {
                    //spawn death particles locally using pooling and colorize them in the player's team color
                    GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                    ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                    if (pColor)
                    {
                        pColor.SetColor(GameManagerSinglePlayer.GetInstance().teamsForSinglePlayer[teamIndex].material.color);
                    }
                }

                //play sound clip on player death
                if (explosionClip)
                {
                    AudioManager.Play3D(explosionClip, transform.position);
                }
            }

            //further changes only affect the local player
            if (!isLocalPlayer)
            {
                return;
            }

            //local player got respawned so reset states
            if (isActive == true)
            {
                ResetPosition();
            }
            else
            {
                //local player was killed, set camera to follow the killer
                camFollow.target = killedBy.transform;
                //disable input
                disableInput = true;
                //display respawn window (only for local player)
                GameManagerSinglePlayer.GetInstance().DisplayDeath();
            }
        }
Beispiel #12
0
        protected virtual void RpcRespawn()
        {
            //toggle visibility for player gameobject (on/off)
            gameObject.SetActive(!gameObject.activeInHierarchy);
            bool isActive = gameObject.activeInHierarchy;

            //the player has been killed
            if (!isActive)
            {
                //detect whether the current user was responsible for the kill
                //yes, that's my kill: take thumbnail via EveryPlay
                if (killedBy == GameManager.GetInstance().localPlayer.gameObject)
                {
                    UnityEveryplayManager.TakeThumbnail();
                }

                if (explosionFX)
                {
                    //spawn death particles locally using pooling and colorize them in the player's team color
                    GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                    ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                    if (pColor)
                    {
                        pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color);
                    }
                }

                //play sound clip on player death
                if (explosionClip)
                {
                    AudioManager.Play3D(explosionClip, transform.position);
                }
            }

            //further changes only affect the local client
            if (!photonView.isMine)
            {
                return;
            }

            //local player got respawned so reset states
            if (isActive == true)
            {
                ResetPosition();
            }
            else
            {
                //local player was killed, set camera to follow the killer
                camFollow.target = killedBy.transform;
                //hide input controls and other HUD elements
                camFollow.HideMask(true);
                //display respawn window (only for local player)
                GameManager.GetInstance().DisplayDeath();
            }
        }
Beispiel #13
0
 //called on all clients after bullet spawn
 //spawn effects or sounds locally, if set
 protected void RpcOnShot()
 {
     if (shotFX)
     {
         PoolManager.Spawn(shotFX, shotPos.position, Quaternion.identity);
     }
     if (shotClip)
     {
         AudioManager.Play3D(shotClip, shotPos.position, 0.1f);
     }
 }
Beispiel #14
0
        public void Instantiate()
        {
            if (obj != null)
            {
                return;
            }
            obj = PoolManager.Spawn(prefab, transform.position, transform.rotation);

            //set the reference on the instantiated object for cross-referencing
            obj.GetComponent <Powerup>().spawner = this;
        }
Beispiel #15
0
        private void CmdShootBullet()
        {
            //spawn bullet using pooling, locally
            GameObject obj = PoolManager.Spawn(bullet, shotPos.position, turret.rotation);
            Bullet     blt = obj.GetComponent <Bullet>();

            blt.owner = gameObject;

            NetworkIdentity networkPrefab = obj.GetComponent <NetworkIdentity>();

            NetworkServer.Spawn(obj, networkPrefab.assetId);
        }
Beispiel #16
0
        public void PlayFX()
        {
            Player player = owner.GetComponent <Player>();

            if (player.shotFX)
            {
                PoolManager.Spawn(player.shotFX, player.shotPos.position, Quaternion.identity);
            }

            if (player.shotClip)
            {
                AudioManager.Play3D(player.shotClip, player.shotPos.position, 0.1f);
            }
        }
Beispiel #17
0
        //check what was hit on collisions
        void OnTriggerEnter(Collider col)
        {
            //cache corresponding gameobject that was hit
            GameObject obj = col.gameObject;
            //try to get a player component out of the collided gameobject
            Player player = obj.GetComponent <Player>();

            //we actually hit a player
            //do further checks
            if (player != null)
            {
                //ignore ourselves & disable friendly fire (same team index)
                if (player.gameObject == owner || player.gameObject == null)
                {
                    return;
                }
                else if (player.teamIndex == owner.GetComponent <Player>().teamIndex)
                {
                    return;
                }

                //create clips and particles on hit
                if (hitFX)
                {
                    PoolManager.Spawn(hitFX, transform.position, Quaternion.identity);
                }
                if (hitClip)
                {
                    AudioManager.Play3D(hitClip, transform.position);
                }

                //on the player that was hit, set the killing player to the owner of this bullet
                //maybe this owner really killed the player, but that check is done in the Player script
                //if (NetworkServer.active == true)
                //    player.killedBy = owner;
            }


            if (NetworkServer.active == true)
            {
                //apply bullet damage to the collided player
                //no need to check if the player is team mate since it will return above if it is a team mate.
                if (player)
                {
                    player.TakeDamage(this);
                }
            }

            PoolManager.Despawn(gameObject);
        }
Beispiel #18
0
        public virtual void Rpc_Killed(GameObject killer)
        {
            Debug.Log("Run on client");
            Debug.Log("Client Killby:" + killer.ToString());

            killedBy = killer;

            Hide(true);

            Debug.Log(gameObject.activeInHierarchy);
            //detect whether the current user was responsible for the kill
            //yes, that's my kill: increase local kill counter
            //can't kill ourselves and add that to the kill counter
            if (!isLocalPlayer && killer == GameManager.GetInstance().localPlayer.gameObject)
            {
                GameManager.GetInstance().ui.killCounter[0].text = (int.Parse(GameManager.GetInstance().ui.killCounter[0].text) + 1).ToString();
                GameManager.GetInstance().ui.killCounter[0].GetComponent <Animator>().Play("Animation");
            }

            if (explosionFX)
            {
                //spawn death particles locally using pooling and colorize them in the player's team color
                GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                if (pColor)
                {
                    pColor.SetColor(GameManager.GetInstance().teams[teamIndex].material.color);
                }
            }

            //play sound clip on player death
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }


            //further changes only affect the local player
            if (isLocalPlayer)
            {
                StartCoroutine(SpawnRoutine());
                //local player was killed, set camera to follow the killer
                camFollow.target = killedBy.transform;
                //disable input
                disableInput = true;
                //display respawn window (only for local player)
                GameManager.GetInstance().DisplayDeath();
            }
        }
Beispiel #19
0
        //set despawn effects and reset variables
        void OnDespawn()
        {
            myRigidbody.velocity        = Vector3.zero;
            myRigidbody.angularVelocity = Vector3.zero;

            //create clips and particles on despawn
            if (explosionFX)
            {
                PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
            }
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }
        }
        //set despawn effects and reset variables
        public void OnDespawn()
        {
            //create clips and particles on despawn
            if (explosionFX && stateWepon == 0)
            {
                PoolManager.Spawn(explosionFX, transform.position, transform.rotation);

                PoolManager.Spawn(ZoneTakeDamage, transform.position, Quaternion.identity);
                GameObject objTakedamage = PoolManager.Spawn(ZoneTakeDamage, transform.position, Quaternion.identity);

                objTakedamage.GetComponent <ZoneTakedamage>().damage = TakedamageBullet();
            }

            else if (hitTextBonfire && stateWepon == 1)
            {
                PoolManager.Spawn(hitTextBonfire, transform.position, Quaternion.identity);
                PoolManager.Spawn(EffectBonfire, transform.position, Quaternion.identity);

                GameObject damagebonfire = PoolManager.Spawn(EffectBonfire, transform.position, Quaternion.identity);
                damagebonfire.GetComponent <BonFire>().damage = TakedamageBullet();
            }
            else if (hitThunder && stateWepon == 2)
            {
                PoolManager.Spawn(hitThunder, transform.position, Quaternion.identity);
                PoolManager.Spawn(hitTextThunder, transform.position, Quaternion.identity);
            }


            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            if (ZoneTakeDamage)
            {
                PoolManager.Spawn(ZoneTakeDamage, transform.position, Quaternion.identity);
                GameObject Spawndamage = PoolManager.Spawn(ZoneTakeDamage, transform.position, Quaternion.identity);
                Spawndamage.GetComponent <ZoneTakedamage>().damage = TakedamageBullet();
            }

            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }
            //reset modified variables to the initial state
            rigi.velocity        = Vector3.zero;
            rigi.angularVelocity = Vector3.zero;
        }
Beispiel #21
0
        //set despawn effects and reset variables
        void OnDespawn()
        {
            //create clips and particles on despawn
            if (explosionFX)
            {
                PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
            }
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            //reset modified variables to the initial state
            myRigidbody.velocity        = Vector3.zero;
            myRigidbody.angularVelocity = Vector3.zero;
        }
Beispiel #22
0
        //the actual respawn routine
        IEnumerator Respawn()
        {
            //stop AI updates
            isDead = true;
            inRange.Clear();
            agent.Stop();

            if (explosionFX)
            {
                //spawn death particles locally using pooling and colorize them in the player's team color
                GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                if (pColor)
                {
                    pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color);
                }
            }

            //play sound clip on player death
            if (explosionClip)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            //toggle visibility for all rendering parts (off)
            ToggleComponents(false);
            //wait global respawn delay until reactivation

            yield return(new WaitForSeconds(GameManager.GetInstance().respawnTime));

            FindObjectOfType <BotSpawner>().Despawn(this.gameObject);


//            toggle visibility again (on)
            ToggleComponents(true);


            //respawn and continue with pathfinding
            targetPoint        = GameManager.GetInstance().GetSpawnPosition(GetView().GetTeam());
            transform.position = targetPoint;
            agent.Warp(targetPoint);
            agent.Resume();
            isDead = false;
        }
Beispiel #23
0
        protected void CmdShootProjectile(short[] position, short angle)
        {
            //get current bullet type

            //calculate center between shot position sent and current server position (factor 0.6f = 40% client, 60% server)
            //this is done to compensate network lag and smoothing it out between both client/server positions
            if (currentBullet > 0)
            {
                Vector3    shotCenter = Vector3.Lerp(shotPos2.position, new Vector3(position[0] / 10f, shotPos2.position.y, position[1] / 10f), 0.6f);
                Quaternion syncedRot  = turret.rotation = Quaternion.Euler(0, angle, 0);

                //spawn bullet using pooling
                GameObject obj = PoolManager.Spawn(bullets[1], shotCenter, syncedRot);
                obj.GetComponent <Bullet>().owner = gameObject;
//                obj.GetComponent<Bullet>().damage = Damage;

                obj.GetComponent <Bullet_Projectile>().stateWepon = StateWepon;

                obj.GetComponent <Bullet_Projectile>().MoveProjectile(shotPos2.forward.normalized, m_BulletSpeed);


//            obj.GetComponent<Bullet>().transform.rotation = shotPos2.rotation;
                GameObject zone = Instantiate(ZoneBome, Vec_ZoneBom, Quaternion.identity);

                BomZone bomZone = zone.GetComponent <BomZone>();
                bomZone.owner = obj;
            }
            //bomZone.alive = true;

            //check for current ammunition
            //let the server decrease special ammunition, if present
            if (PhotonNetwork.isMasterClient && currentBullet != 0)
            {
                //if ran out of ammo: reset bullet automatically
                GetView().DecreaseAmmo(1);
            }

            //send event to all clients for spawning effects
            if (shotFX || shotClip)
            {
                RpcOnShot();
            }
        }
Beispiel #24
0
        public void RpcDie(short senderId)
        {
            gameObject.SetActive(false);
            killedBy = senderId > 0 ? ClientScene.FindLocalObject(new NetworkInstanceId((uint)senderId)) : null;
            bIsAlive = false;
            // TODO: ScoreBegin
            if (explosionFX != null)
            {
                //spawn death particles locally using pooling and colorize them in the player's team color
                GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                if (pColor)
                {
                    pColor.SetColor(GameManager.GetInstance().teams[teamIndex].material.color);
                }
            }

            //play sound clip on player death
            if (explosionClip != null)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            if (isServer)
            {
                agent.Warp(GameManager.GetInstance().GetSpawnPosition(teamIndex));
            }

            if (controller != null)
            {
                controller.Stop();
            }

            if (isLocalPlayer)
            {
                if (killedBy != null)
                {
                    camFollow.target = killedBy.transform;
                }
                camFollow.HideMask(true);
                GameManager.GetInstance().DisplayDeath();
            }
        }
Beispiel #25
0
        public void ShootAndLandMineUi(Vector2 direction = default(Vector2))
        {
            UIJoystick Uijoy = FindObjectOfType <UIJoystick>();

            //shoot bullet on left mouse click
            if (projectile == false && landmine == false)
            {
                Uijoy.UIBullet();

                Shoot();
            }
            else if (landmine == true && projectile == false)
            {
                GameObject obj = PoolManager.Spawn(bullets[2], transform.position, Quaternion.identity);

                obj.GetComponent <Landmine>().stateWepon = StateWepon;

                landmine = false;
            }
        }
Beispiel #26
0
        // shoots a bullet in the direction passed in
        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);
                Bullet     blt = obj.GetComponent <Bullet>();

                if (shotFX)
                {
                    PoolManager.Spawn(shotFX, shotPos.position, Quaternion.identity);
                }
                if (shotClip)
                {
                    AudioManager.Play3D(shotClip, shotPos.position, 0.1f);
                }
            }
        }
Beispiel #27
0
        IEnumerator I_Bonfire(int damage)
        {
            int hit = 3;

            if (EF_Bornfire)
            {
                AudioManager.Play3D(EF_Bornfire, shotPos.position, 6f);
            }


            for (int i = 0; i < hit; i++)
            {
                if (EffectBonFire)
                {
                    EffectBonFire.SetActive(true);
                }

//                    HitBonFire.SetActive(true);
                if (HitBonFire)
                {
                    PoolManager.Spawn(HitBonFire, transform.position, Quaternion.identity);
                    TakeDamageBot(damage / 2);

                    if (Hit_TextBornfire)
                    {
                        AudioManager.Play3D(Hit_TextBornfire, shotPos.position, 0.1f);
                    }
                }

                yield return(new WaitForSeconds(2));



                if (EffectBonFire)
                {
                    EffectBonFire.SetActive(false);
                }
            }
        }
Beispiel #28
0
        void CmdShoot(short xPos, short zPos)
        {
            //calculate center between shot position sent and current server position (factor 0.6f = 40% client, 60% server)
            //this is done to compensate network lag and smoothing it out between both client/server positions
            Vector3 shotCenter = Vector3.Lerp(shotPos.position, new Vector3(xPos / 10f, shotPos.position.y, zPos / 10f), 0.6f);

            //spawn bullet using pooling, locally
            GameObject obj = PoolManager.Spawn(bullets[currentBullet], shotCenter, turret.rotation);
            Bullet     blt = obj.GetComponent <Bullet>();

            blt.owner = gameObject;

            //if it is a static bullet (such as a mine), overwrite Y-position with current tank height, so it spawns at the ground
            if (blt.speed == 0)
            {
                shotCenter.y           = transform.position.y;
                obj.transform.position = shotCenter;
            }

            //spawn bullet networked
            NetworkServer.Spawn(obj, bullets[currentBullet].GetComponent <NetworkIdentity>().assetId);

            //check for current ammunition
            //if ran out of ammo: reset bullet
            if (currentBullet != 0)
            {
                ammo--;
                if (ammo <= 0)
                {
                    currentBullet = 0;
                }
            }

            //send event to all clients for spawning effects
            if (shotFX || shotClip)
            {
                RpcOnShot();
            }
        }
        /// <summary>
        /// Play sound clip passed in in 3D space, with optional random pitch (0-1 range).
        /// Automatically creates an audio source for playback using our PoolManager.
        /// </summary>
        public static void Play3D(AudioClip clip, Vector3 position, float pitch = 0f)
        {
            //cancel execution if clip wasn't set
            if (clip == null)
            {
                return;
            }
            //calculate random pitch in the range around 1, up or down
            pitch = UnityEngine.Random.Range(1 - pitch, 1 + pitch);

            //activate new audio gameobject from pool
            GameObject audioObj = PoolManager.Spawn(instance.oneShotPrefab, position, Quaternion.identity);
            //get audio source for later use
            AudioSource source = audioObj.GetComponent <AudioSource>();

            //assign properties, play clip
            source.clip  = clip;
            source.pitch = pitch;
            source.Play();

            //deactivate audio gameobject when the clip stops playing
            PoolManager.Despawn(audioObj, clip.length);
        }
Beispiel #30
0
        //check what was hit on collisions
        void OnTriggerEnter(Collider col)
        {
            //cache corresponding gameobject that was hit
            GameObject obj = col.gameObject;
            //try to get a player component out of the collided gameobject
            NetworkedPlayer player = obj.GetComponent <NetworkedPlayer>();

            //we actually hit a player
            //do further checks
            if (player != null)
            {
                //ignore ourselves
                if (player.gameObject == owner || player.gameObject == null)
                {
                    return;
                }

                //create clips and particles on hit
                if (hitFX)
                {
                    PoolManager.Spawn(hitFX, transform.position, Quaternion.identity);
                }
                if (hitClip)
                {
                    AudioManager.Play3D(hitClip, transform.position);
                }
            }

            //apply bullet damage to the collided player
            if (player)
            {
                player.TakeDamage(this);
            }
            //despawn gameobject
            Destroy(gameObject);
        }