So i have a Generator that spawns minions from the front, it uses a timer to spawn, all ok, but when i reset the game, the generator's position remains in the last position, unless i click 2 times(in a small interval of time)
code looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
public Transform PlatformGenerator;
private Vector3 platformStartPoint;
public Transform BackgroundGenerator;
private Vector3 backgroundStartPoint;
public Transform frontMinionsGenerator;
private Vector3 frontMinionsGeneratorStartPoint;
public PlayerController thePlayer;
private Vector3 playerStartPoint;
public Transform tantarGenerator;
private Vector3 tantarGeneratorStartPoint;
public Transform flyGenerator;
private Vector3 flyGeneratorStartPoint;
private PlatformDestroyer[] platformList;
private ScoreManager theScoreManager;
public DeathMenu theDeathScreen;
// Use this for initialization
void Start() {
platformStartPoint = PlatformGenerator.position;
backgroundStartPoint = BackgroundGenerator.position;
playerStartPoint = thePlayer.transform.position;
tantarGeneratorStartPoint = tantarGenerator.position;
frontMinionsGeneratorStartPoint = frontMinionsGenerator.position;
flyGeneratorStartPoint = flyGenerator.position;
theScoreManager = FindObjectOfType();
}
public void RestartGame()
{
theScoreManager.scoreIncreasing = false;
thePlayer.gameObject.SetActive(false);
theDeathScreen.gameObject.SetActive(true);
}
public void Reset()
{
theDeathScreen.gameObject.SetActive(false);
platformList = FindObjectsOfType();
for (int i = 0; i < platformList.Length; i++)
{
platformList[i].gameObject.SetActive(false);
}
thePlayer.transform.position = playerStartPoint;
tantarGenerator.position = tantarGeneratorStartPoint;
frontMinionsGenerator.position = frontMinionsGeneratorStartPoint;
PlatformGenerator.position = platformStartPoint;
BackgroundGenerator.position = backgroundStartPoint;
flyGenerator.position = flyGeneratorStartPoint;
thePlayer.gameObject.SetActive(true);
DestroyAllMosquitos();
DestroyAllRats();
thePlayer.moveSpeed = thePlayer.moveSpeedStore;
thePlayer.speedIncreaseMilestone = thePlayer.speedIncreaseMilestoneStore;
theScoreManager.scoreCount = 0;
theScoreManager.scoreIncreasing = true;
}
void DestroyAllMosquitos()
{
GameObject[] listaTantari = GameObject.FindGameObjectsWithTag("Tantar");
foreach (GameObject go in listaTantari)
{
go.SetActive(false);
}
}
void DestroyAllRats()
{
GameObject[] listaRats = GameObject.FindGameObjectsWithTag("Rat");
foreach (GameObject go in listaRats)
{
go.SetActive(false);
}
}
}
↧