void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.layer == LayerMask.NameToLayer("Enemy")) { healthHandler.takeDamage(0.5f); Debug.Log(StaticPlayer.getHealth()); } }
void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("Player")) { StaticPlayer.DamagePlayer(100f); } this.gameObject.SetActive(false); }
void OnTriggerEnter2D(Collider2D col) { // The basic upgrades better the weapon for 8% switch (powerupType) { case Type.FiringSpeed: StaticPlayer.UpgradeFiringSpeed(); break; case Type.ShotMoveSpeed: StaticPlayer.UpgradeBulletSpeed(); break; case Type.Damage: StaticPlayer.UpgradeDamage(); break; case Type.MoveSpeed: StaticPlayer.UpgradeMoveSpeed(); break; case Type.WeaponTypeMagnum: if (StaticPlayer.weaponType != 0) { StaticPlayer.SwitchToWeapon(0); Player.plrInstance.RefreshSprite(); } break; case Type.WeaponTypeRifle: if (StaticPlayer.weaponType != 1) { StaticPlayer.SwitchToWeapon(1); Player.plrInstance.RefreshSprite(); } break; case Type.WeaponTypeShotgun: if (StaticPlayer.weaponType != 2) { StaticPlayer.SwitchToWeapon(2); Player.plrInstance.RefreshSprite(); } break; case Type.WeaponTypeSniper: if (StaticPlayer.weaponType != 3) { StaticPlayer.SwitchToWeapon(3); Player.plrInstance.RefreshSprite(); } break; case Type.Health: StaticPlayer.HealPlayer(); Player.plrInstance.HealthUpdate(); break; } this.gameObject.SetActive(false); }
public void StartGameplay() { StaticPlayer.ResetStats(); SceneManager.LoadScene("GamePlay"); }
public void takeDamage(float damage) { StaticPlayer.setHealth(StaticPlayer.getHealth() - damage); }
void Start() { _playerHealth = StaticPlayer.getHealth(); updateUI(); }
public void SwitchWeaponTo(int weaponIndex) { StaticPlayer.SwitchToWeapon(weaponIndex); player.RefreshSprite(); }
void FixedUpdate() { // If we are alive, we can move etc. if (StaticPlayer.currHP > 0) { float horizontalMove = Input.GetAxisRaw("Horizontal"); float verticalMove = Input.GetAxisRaw("Vertical"); // Using the touch-based joystick if we build for Android #if UNITY_ANDROID switch (StaticPlayer.joystickType) { case 0: horizontalMove = joystickFloating.Horizontal; verticalMove = joystickFloating.Vertical; break; case 1: horizontalMove = joystickFixed.Horizontal; verticalMove = joystickFixed.Vertical; break; default: horizontalMove = joystickFloating.Horizontal; verticalMove = joystickFloating.Vertical; break; } #endif Vector2 moveDirection = new Vector2(horizontalMove, verticalMove).normalized; plrRB.velocity = moveDirection * StaticPlayer.moveSpeed; // We check for the closest enemy/target every time we stop if (horizontalMove == 0 && verticalMove == 0) { plrMoving = false; if (!targetUpdated) { CheckForClosest(); targetUpdated = true; } } else { plrMoving = true; targetUpdated = false; } // We face the direction of the movement velocity if we are moving, otherwise we aim and shoot if (plrMoving) { Vector2 lookDir = new Vector2(horizontalMove, verticalMove); RotateSpriteToDirection(lookDir); indicatorTarget.SetActive(false); targetTF = null; playerLegsObj.SetActive(true); } else { if (targetTF) // We have a target -> Shooting towards it, updating the indicator { ShootAtClosest(); if (targetUpdated) { indicatorTF.position = targetTF.position; indicatorTarget.SetActive(true); } } else // We don't have a target -> Checking constantly for new targets { CheckForClosest(); } playerLegsObj.SetActive(false); } // Checking for just taps on screen: allowing the player to switch the aiming target without actually moving the joystick if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Ended) { CheckForClosest(); } } if (beingDamaged) { // There is a delay so that the player's health is not drained in an instant if (damageTimer > damageDelay) { StaticPlayer.DamagePlayer(50f); // Current damage is static amount } } else { if (damageTimer > damageDelay) { playerSpriteRend.color = Color.white; } } // Making the target indicator disappear if there is no target Transform if (!targetTF) { indicatorTarget.SetActive(false); } shootTimer += Time.fixedDeltaTime; damageTimer += Time.fixedDeltaTime; } else // Player is dead { if (StaticPlayer.statusChanged) { playerLegsObj.SetActive(false); gameOverTextObj.SetActive(true); tryAgainButton.SetActive(true); indicatorTarget.SetActive(false); StaticPlayer.alive = false; playerSpriteRend.sprite = playerSprites[0]; playerSpriteRend.color = Color.white; plrRB.velocity = Vector2.zero; this.GetComponent <CircleCollider2D>().enabled = false; StaticPlayer.statusChanged = false; } } }