public void RepairDamage(float repairAmount) { if (!GameInformation.IsPVP() || (controllable && GameInformation.IsPVP())) { healthLevel += repairAmount; } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Bullet") { var bullet = other.gameObject.GetComponent <Bullet>(); if (GameInformation.IsPVP()) { // Don't kill yourself!s if (bullet.owner == transform.parent.GetComponent <NetworkedPlayer>().PlayerID) { return; } } parentHealth.InflictDamage(bullet.Damage); other.gameObject.GetComponent <BulletDestoryScript>().DestroyOnImpact(); if (GameInformation.IsPVP() && bullet.owner == "Player") { var player = GameObject.FindGameObjectWithTag("Player"); if (player) { player.GetComponent <PlayerScore>().AddScore(1.0f); } } } }
public void InflictDamage(float damage) { if (!GameInformation.IsPVP() || (controllable && GameInformation.IsPVP())) { healthLevel -= damage; } }
// Update is called once per frame void Update() { if (!GameInformation.IsPVP() || (GameInformation.IsPVP() && controllable)) { UpdateMouseCursorAngle(); FireCannons(); } }
void Update() { if (playGameRequest && fadeGameHandler.IsFullyFadedIn()) { playGameRequest = false; fadeGameHandler.FadeOut(); Application.LoadLevel(GameInformation.IsPVP() ? 7 : 1); } }
public void FireGun() { if (GameInformation.IsPVP()) { fireScript.Fire(transform.parent.transform.parent.GetComponent <NetworkedPlayer>().PlayerID, firePosition, fireRotation); } else { fireScript.Fire(transform.parent.transform.parent.tag, firePosition, fireRotation); } hasFired = controller.controllable; }
bool IsCloseToPlayer(Vector3 position) { if (GameInformation.IsPVP()) { var player = GameObject.FindGameObjectWithTag("Player"); if (player != null) { const float maxDistance = 30.0f; return((player.transform.position - position).magnitude <= maxDistance); } } return(true); }
// Update is called once per frame void Update() { if (GameInformation.IsPVP() && !controllable) { return; } mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); controller.AimWeapon(mousePos); if (Input.GetMouseButtonDown(0)) { controller.FireWeapon(); } }
void InitialiseHealthBar() { if (!HasHealthBar()) { if ((!GameInformation.IsPVP() || (controllable && GameInformation.IsPVP()))) { var player = GameObject.FindWithTag("Player"); if (player != null) { healthBar = GameObject.FindWithTag("PlayerHealth"); } } else if (!controllable && GameInformation.IsPVP()) { var floatingHealthBar = transform.parent.transform.FindChild("FloatingHealthBar"); healthBar = floatingHealthBar.FindChild("HealthBar").gameObject; floatingHealthBarText = floatingHealthBar.FindChild("Canvas").FindChild("Text").gameObject; } } if (HasHealthBar() && !initialised) { initialised = true; if (healthBar.GetComponent <RectTransform>() != null) { hasScreenSpaceBar = true; maxBarWidth = healthBar.GetComponent <RectTransform>().rect.width; barHeight = healthBar.GetComponent <RectTransform>().rect.height; } else { maxBarWidth = healthBar.transform.localScale.x; barHeight = healthBar.transform.localScale.y; } } }
// Update is called once per frame void Update() { if (GameInformation.IsPVP()) { if (controller.controllable) { firePosition = fireScript.FirePosition(); fireRotation = fireScript.FireRotation(); UpdateRotation(); } if (shouldFire) { FireGun(); shouldFire = false; } } else { firePosition = fireScript.FirePosition(); fireRotation = fireScript.FireRotation(); UpdateRotation(); } }
void FixedUpdate() { if (GameInformation.IsPVP() && !controllable) { return; } var rb = GetComponent <Rigidbody2D> (); if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { forwardForce.x = transform.up.x * forwardSpeed; forwardForce.y = transform.up.y * forwardSpeed; rb.AddForce(forwardForce); } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { rb.AddTorque(rotationSpeed); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { rb.AddTorque(-rotationSpeed); } }
void Update() { if (player == null) { player = GameObject.FindWithTag("Player"); if (player != null) { playerHealth = player.GetComponent <Health> (); if (playerHealth == null) { Debug.LogError("Player requires health bar"); } } return; } if (toMenuRequest || toPlayRequest) { if (fadeGameHandler.IsFullyFadedIn()) { fadeGameHandler.FadeOut(); if (!GameInformation.IsPVP()) { Application.LoadLevel(toMenuRequest ? 0 : 1); } else { PhotonNetwork.Disconnect(); Application.LoadLevel(toMenuRequest ? 0 : 7); } } } else if (!isGameOver) { if (Input.GetKeyDown(KeyCode.Escape) || forceLoseGame || !playerHealth.IsAlive) { isGameOver = true; hasLostGame = true; } // Currently no way to win PVP! if (!GameInformation.IsPVP()) { if (forceWinGame || (enemies.TrueForAll(enemy => enemy == null) && islands.TrueForAll(island => island.GetComponent <IslandDiscoveryTrigger>().IsDiscovered()))) { hasLostGame = false; isGameOver = true; } } if (isGameOver) { sharedSoundHandler.StopPlayingGame(); sharedSoundHandler.StartPlayingMenu(); if (!GameInformation.IsPVP()) { player.SetActive(false); } else { player.GetComponent <Health>().SetHealthLevel(0.0f); } if (hasLostGame) { gameLostImage.GetComponent <UnityEngine.UI.Image>().enabled = true; } else { gameWonImage.GetComponent <UnityEngine.UI.Image>().enabled = true; } } } }