My random script work incorrect!
I have MoveScript and RandomScript. My randomScript works like this: It has a GameObject array. In it, I put the object N number Cube1. Cube1 has a Movescript script that moves it to FPSControler. But when I Destroy Cube1 RandomScript stops working. I put Cube1 in the Assets folder to fix the problem, but MoveScript stopped referring to FPSController. How do I solve the problem?
My MoveScript:
void Update () {
transform.position = Vector3.MoveTowards(transform.position, FPSController.position, Time.deltaTime * 2);
if (transform.position == FPSController.position)
{
Debug.Log("Game Over");
}
}
My RandomScript:
// Use this for initialization
public GameObject[] enemies ;
public Vector3 spawnValues;
public float spawnWait;
public float spawnMostWait;
public float spawnLessWait;
public int startWait;
public bool stop;
int Rendenemy;
public Transform FPSController;
void Start () {
StartCoroutine(waitSpawner());
}
// Update is called once per frame
void Update () {
spawnWait = Random.Range(spawnLessWait, spawnMostWait);
}
IEnumerator waitSpawner()
{
yield return new WaitForSeconds(startWait);
while (!stop) {
Rendenemy = Random.Range(0, 2);
Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x ), 1, Random.Range(-spawnValues.z, spawnValues.z));
Instantiate(enemies[Rendenemy], spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
yield return new WaitForSeconds(spawnWait);
}
}
Your answer
Follow this Question
Related Questions
How do I sync health meters via Photon? 0 Answers
Object moves on itself, how to write an "if statement'? 0 Answers
Error building Player: CommandInvokationFailure: Failed to re-package resources. 0 Answers
How would you save anti aliasing or v-sync stuff that are like QualitySettings.antiAliasing = 2; 0 Answers
Unity 5.3 UI Button wont set Select state via script after the parent has been set inactive 0 Answers