private PlayerSpaceShip SpawnPlayerUnit() { GameObject spawnedPlayerObject = _playerSpawner.Spawn(); PlayerSpaceShip playerShip = spawnedPlayerObject.GetComponent <PlayerSpaceShip>(); return(playerShip); }
public PlayerSpaceShip Spawn() { GameObject spawnedObject = Instantiate(_prefabToSpawn, transform.position, transform.rotation); PlayerSpaceShip _spawnedPlayer = spawnedObject.GetComponent <PlayerSpaceShip> (); _spawnedPlayer.Spawner = this; return(_spawnedPlayer); }
protected virtual void OnTriggerEnter2D(Collider2D other) { PlayerSpaceShip player = other.GetComponent <PlayerSpaceShip>(); if (player != null) { // Destroys the power-up item Destroy(gameObject); } }
protected void OnTriggerEnter2D(Collider2D other) { PlayerSpaceShip player = other.GetComponent <PlayerSpaceShip>(); if (player != null) { player.GivePowerup(gameObject, duration); } Destroy(gameObject); }
private void Update() { if (player == null) { player = GameObject.Find("PlayerUnit(Clone)").GetComponent <PlayerSpaceShip>(); } else { text.text = "Weapon Timer: " + player.PowerUpTimer + "\nPlayer Life: " + player.Health.CurrentHealth; } }
protected override void OnTriggerEnter2D(Collider2D other) { PlayerSpaceShip player = other.GetComponent <PlayerSpaceShip>(); if (player != null) { player.CollectHealthPowerUp(healthBoost); // Destroys the health item Destroy(gameObject); } }
protected override void OnTriggerEnter2D(Collider2D other) { PlayerSpaceShip player = other.GetComponent <PlayerSpaceShip>(); if (player != null) { player.CollectExtraWeaponPowerUp(powerUpDuration); // Destroys the power-up item Destroy(gameObject); } }
public PlayerSpaceShip SpawnPlayer() { PlayerSpaceShip player = null; GameObject playerObject = _playerSpawner.Spawn(); if (playerObject != null) { player = playerObject.GetComponent <PlayerSpaceShip>(); } player.BecomeImmortal(); return(player); }
private void Update() { // In the case of just starting the game or the // player ship dying, the player ship is retrieved if (player == null) { player = LevelController.Current.Player; } else { UpdateExtraWeaponTime(); UpdateExtraWeaponTimeText(); } }
private PlayerSpaceShip SpawnPlayer() { PlayerSpaceShip playerShip = null; GameObject playerObject = playerSpawner.Spawn(); if (playerObject != null) { playerShip = playerObject.GetComponent <PlayerSpaceShip>(); } playerShip.BecomeInvincible(); this.playerShip = playerShip; return(playerShip); }
public void LifeLost(bool outOfLives) { // If the player runs out of lives, // the game over screen is displayed if (outOfLives) { playerShip = null; GameManager.Instance.GameWon = false; GoToState(GameStateType.GameOver); } else { // Lowers score GameManager.Instance.CurrentScore += scorePenaltyFromDeath; SpawnPlayer(); } }
protected void Start() { _playerObject = _playerSpawner.Spawn(); _player = _playerObject.GetComponent <PlayerSpaceShip>(); StartCoroutine(SpawnEnemies()); int moveTargetCount = transform.Find("MoveTargets").transform.childCount; _enemyMoveTargets = new GameObject[moveTargetCount]; for (int i = 0; i < _enemyMoveTargets.Length; i++) { _enemyMoveTargets[i] = transform.Find("MoveTargets").transform.GetChild(i).gameObject; } _scoreText.text = "" + GameManager.Instance.CurrentScore; }
protected override void Die() { // Destroys the gameobject. Otherwise Unity will see two player ships. base.Die(); // Respawn if lives left. if (_lives > 0) { // Spawn new ship. PlayerSpaceShip newShip = Spawner.Spawn(); // The new ship has one life less; newShip.Lives = Lives - 1; Debug.Log("Respawn with " + (Lives - 1).ToString() + " lives left."); // Make new ship immortal! newShip.MakeImmortal(); } else { Debug.Log("Player died"); } }
protected override void PowerUpPlayer(GameObject player) { PlayerSpaceShip _player = player.GetComponent <PlayerSpaceShip>(); _player.AddPowerUpTimer(5); }
protected void Start() { // Starts a new coroutine. StartCoroutine(SpawnRoutine()); PlayerSpaceShip player = SpawnPlayerUnit(); }