Controller gives NullReferenceException and Teleporter is unresponsive when collided
I'm relatively new to the Unity Engine. I'm making a simple game where after the player collects every object in order to reach another scene. However, the teleporter has no response after the player collects every object and collides with the teleporter.
Does anyone know what might have gone wrong with my code? Any help would be appreciated. Thanks. Compiler Error Observation: Console gives a NullReference error everytime the game is running.
Controller.cs(C#)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Controller : MonoBehaviour {
public GameObject Ball;
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count = 4;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
countText.text = "";
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);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pickup"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
//Destroy (other.gameObject);
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count == 4);
{
winText.text = "You Win!";
}
}
TeleportPad.cs
public class TeleportPad : MonoBehaviour {
private GameObject Teleport;
public Text winText;
void Start ()
{
winText.text = "";
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Teleport") &
winText.text == "You Win!")
{
gameObject.SetActive (true);
//Destroy (other.gameObject);
Application.LoadLevel(2);
}
}
} [2]: /storage/temp/54021-uniq.png
@triggerdog this is not getting us anywhere. Even if you upload your project and I debug it for you it's not going to help you get very far, because for sure, you will get stuck pretty soon in another part of your project.
In fact, this forum is not a place for getting help with debugging and compiler errors, but some questions do get passed through the forum moderators.
The best thing for you to do in order to learn how to use Unity, as well as general program$$anonymous$$g principles is to explore the Learn section:
Your answer
Follow this Question
Related Questions
Problem referencing an int inside of a dictionary. 0 Answers
Why is my component coming back as null? 1 Answer
Varialbes on prefab script always null 0 Answers
NullRefrenceException - Cant find the cost 1 Answer
NullReferenceException: Object reference not set to an instance of an object, again 2 Answers