I am building off of the RollABall tutorial to replace a prefab cube (Pickup3) with another prefab cube (Pickup2) after a timer counts down from 10. The bad/goodCubes are already linked with their respected prefabs but when the timer goes to 0, nothing happens.
public class playerController : MonoBehaviour {
public float timeForEvent = 0;
public float current_time;
public bool isFinished = false;
public Text countText;
public GameObject goodCube;
public GameObject badCube;
private Rigidbody rb;
private int count;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
count = 0;
setCountText ();
current_time = 0;
}
void FixedUpdate () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
if (!isFinished)
{
current_time = current_time - Time.deltaTime;
}
if (current_time <= 0)
{
current_time = 0;
isFinished = true;
Invoke ("replaceCubes", 0);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pickup"))
{
other.gameObject.SetActive (false);
count = count + 1;
setCountText ();
Invoke ("init", 0);
isFinished = false;
current_time = 10;
}
if (other.gameObject.CompareTag ("Pickup3"))
{
other.gameObject.SetActive (false);
count = count + 1;
}
}
void replaceCubes()
{
if (isFinished && gameObject.tag == "Pickup3")
{
Instantiate (badCube, transform.position, transform.rotation);
gameObject.SetActive (false);
}
}
}
I realize its a bit messy but anyone have an idea where I went wrong?