private void ExplodeShell() { // Play explosion effect Instantiate(explosionEffect, transform.position, Quaternion.identity); // Makes a layer into a layermask so that it may be used in physics raycasts LayerMask tankBodyLayer = LayerMask.GetMask("TankBodies"); // Gathers all entity colliders in the explosion's radius Collider[] tanksInRadius = Physics.OverlapSphere(transform.position, projectileExplosionRadius, tankBodyLayer.value); // Iterates through each of the tanks foreach (Collider tank in tanksInRadius) { // FIXME: Realistically, this won't cause performance drops, as a tank shell will rarely hit more than 2 // gameobjects at a time, but using GetComponent in this manner is not optimal performance-wise. TankBase tankController = tank.transform.root.gameObject.GetComponent <TankBase>(); // Reduces tank health tankController.Health = tankController.Health - projectileDamage; } // Destroys the shell // FIXME: Realistically, this too won't cause performance drops, as there won't be too many shells being created // or destroyed too frequently. Still, the ideal way of doing this performance-wise is through object pooling if (projectileBounces <= 0) { Destroy(gameObject); } }
private void Die(string playerWhoKilled) { // All clients should update the dead player controllers properties IsActive = false; _myTankScript.TankDie(); // Only the dead player should destroy their tank and call the respawn stuff if (photonView.IsMine) { double time = PhotonNetwork.Time; _myGUI.Splash_Died(playerWhoKilled); StartCoroutine(_myGUI.UpdateTimer(time + 3.0)); StartCoroutine(WaitToRespawn(time + 3.0)); } _myTankScript = null; _myTankBody = null; }
private void RpcSetTankBody(int viewID) { if (!photonView.IsMine) { _myTankBody = PhotonView.Find(viewID).gameObject; } _myTankBody.transform.parent = transform; _myTankScript = _myTankBody.GetComponent <TankBase>(); _myTankScript.ChangeColor(OwnStats.Color); _myTankScript.SetPlayerID(OwnStats.PlayerID); OwnStats.Curr_Health = OwnStats.Max_Health = _myTankScript.GetHealth(); _myGUI.UpdateHealth(); if (photonView.IsMine) { _myTankScript.SM.PlaySFX(SFX.Start); } }
public TankTurret(TankBase tank, float turretRotationSpeed, float cannonRotationSpeed) { _rotation=new TransformableAngle(turretRotationSpeed,0); _cannon = new TankCannon(tank, cannonRotationSpeed); }
public TankHealth(TankBase tank,float maxHealth) { _tank = tank; CurrentHealth = MaxHealth = maxHealth; }
public void SetOwnerTank(TankBase t) { ownerTank = t; }
private void InitBattlefield(TankBase tankMock) { _tankControllerContext.Battlefield = new Battlefield(_tankControllerContext.TerrainMock); _tankControllerContext.Battlefield.AllTanks.Add(tankMock); }
public void Setup() { _tankMock = Substitute.For<TankBase>(); }