- Home /
This question was
closed Aug 07, 2017 at 04:42 PM by
FortisVenaliter for the following reason:
Problem is not reproducible or outdated. No question included.
Help needed in invoke method... im trying to make the invoke delay start of the next scene but i couldn't?
using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
private bool onGround = false;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && onGround == true) {
Vector3 jump = new Vector3 (0.0f, 400.0f, 0.0f);
rb.AddForce (jump);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "winText") {
Invoke ("minigame2", 100.0f);
}
if (other.gameObject.CompareTag ("Pick Up")) {
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
if (count == 14)
{SceneManager.LoadScene("minigame2");
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Ground") {
onGround = true;
}
}
void OnCollisionExit(Collision other)
{
if (other.gameObject.tag == "Ground") {
onGround = false;
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 14)
{
winText.text = "You Win!";
}
}
}
Comment