I am trying to make a tutorial level when the first object spawns everything works (text, time slows down, etc). But when the second object spawns it starts spawning non stop. I am not getting any errors.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class tutorialSpawn : MonoBehaviour {
public GameObject fisrtObjectRef, firstObjectInstance;
public GameObject secondObjectRef, secondObjectInstance;
public Image firstMessage;
public Text GoalIsActivated;
bool startSpawn= true;
void Start () {
SpawnFirst ();
HideUI (firstMessage);
GoalIsActivated.text = "";
}
void Update () {
if (firstObjectInstance && firstObjectInstance.transform.position.y <= 0) {
ShowFirstMeassage ();
}
if (firstObjectInstance == null) {
HideUI (firstMessage);
GoalIsActivated.text = "The Goal Is Now Activated";
SpawnSecond();
}
if (secondObjectInstance && secondObjectInstance.transform.position.y <= 0 && startSpawn==true) {
ShowSecondMeassage();
}
}
void SpawnFirst() {
Vector3 v = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
firstObjectInstance = Instantiate(fisrtObjectRef, v, Quaternion.identity) as GameObject;
}
void SpawnSecond() {
Vector3 v = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
secondObjectInstance = Instantiate(secondObjectRef, v, Quaternion.identity) as GameObject;
startSpawn = false;
}
void ShowFirstMeassage() {
firstObjectInstance.GetComponent<Rigidbody>().useGravity = false;
firstObjectInstance.GetComponent<Rigidbody>().velocity = Vector3.zero;
ShowUI (firstMessage);
}
void ShowSecondMeassage() {
secondObjectInstance.GetComponent<Rigidbody> ().useGravity = false;
secondObjectInstance.GetComponent<Rigidbody> ().velocity = Vector3.zero;
}
void HideUI (Image uiImage) {
uiImage.color = new Color(uiImage.color.r, uiImage.color.g, uiImage.color.b, 0);
}
void ShowUI (Image uiImage) {
uiImage.color = new Color(uiImage.color.r, uiImage.color.g, uiImage.color.b, 1);
}
}