// Start is called before the first frame update void Start() { StartCoroutine(RandomMovement()); Level_Controller.AddEnemy("Slime"); health = maxHealth; healthBarLocalScale = healthBar.localScale; }
void AddPlayer() { Level_Controller currentController = FindObjectOfType <Level_Controller>(); if (numberOfPlayers >= maxNumberOfPlayers) { return; //TODO add text saying couldn't add new player } GameObject _newPlayer = (GameObject)Instantiate(playerPrefab); GetLevelController(this.sceneName).SpawnPlayer(_newPlayer); _newPlayer.GetComponent <Player_Controller>().playerNum = numberOfPlayers; DontDestroyOnLoad(_newPlayer); _newPlayer.GetComponent <Player_Controller>().SetupPlayer(); _newPlayer.name = "Player " + numberOfPlayers; if (numberOfPlayers > 0) { Destroy(_newPlayer.GetComponent <AudioListener>()); } numberOfPlayers += 1; players.Add(_newPlayer); //set the camera positions for each player, the old players should be updated too foreach (GameObject _player in players) { _player.GetComponent <Player_Controller>().SetupPlayer(); } }
void Start() { if (Instanse == null) { Instanse = this; } sceneIndex = SceneManager.GetActiveScene().buildIndex; levelComplete = PlayerPrefs.GetInt("LevelComplete"); }
// Update is called once per frame void Update() { healthBar.localScale = new Vector3(health / maxHealth * healthBarLocalScale.x, healthBarLocalScale.y, healthBarLocalScale.z); if (health <= 0.0f) { Level_Controller.RemoveEnemy("Mole"); deathRemains.transform.position = transform.position; Instantiate(deathRemains); Destroy(gameObject); } }
void Awake() { if (instance != null) { Debug.Log("More than one Game Controller in scene!"); DestroyImmediate(gameObject); return; } initializeObject(); instance = this; DontDestroyOnLoad(gameObject); }
public void Die() { //Go to level spawn Level_Controller _levelController = gameController.GetLevelController(gameController.sceneName); if (_levelController != null) { _levelController.SpawnPlayer(this.gameObject); } else { Debug.Log("No Level Controller in this scene please add one"); } }
void AddPlayers() { Level_Controller currentController = FindObjectOfType <Level_Controller>(); for (int i = 0; i < numberOfPlayers; i++) { GameObject _newPlayer = (GameObject)Instantiate(playerPrefab); Camera _cam = Instantiate(camPrefab).GetComponent <Camera>(); GetLevelController(this.sceneName).SpawnPlayer(_newPlayer); _newPlayer.GetComponent <Player_Controller>().playerNum = i; _newPlayer.GetComponent <Player_Controller>().mainCamera = _cam; DontDestroyOnLoad(_newPlayer); DontDestroyOnLoad(_cam); _newPlayer.GetComponent <Player_Controller>().SetupPlayer(); _newPlayer.name = "Player " + i; players.Add(_newPlayer); } }
public void Die() { //check if player has already died infoText.text = "You Died"; //Go to level spawn Level_Controller _levelController = gameController.GetLevelController(currentScene.name); if (_levelController != null) { _levelController.SpawnPlayer(this.gameObject); } else { print("No Level Controller in this scene please add one"); } //reset health to full healthScript.Reset(); }
// Update is called once per frame void Update() { healthBar.localScale = new Vector3(health / maxHealth * healthBarLocalScale.x, healthBarLocalScale.y, healthBarLocalScale.z); if (moving == false) { StartCoroutine(RandomMovement()); } if (Vector2.Distance(player.transform.position, transform.position) < 1.5f && attackCooldown == false) { StartCoroutine(AttackPlayer()); } if (health <= 0.0f) { Level_Controller.RemoveEnemy("Slime"); deathRemains.transform.position = transform.position; Instantiate(deathRemains); Destroy(gameObject); } }