Why do I get a NullReferenceException
This is my Error: NullReferenceException: Object reference not set to an instance of an object PlayerJump.OnTouchDown () (at Assets/Scripts/PlayerJump.cs:17) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) TouchInput:Update() (at Assets/Scripts/TouchInput.cs:48)
I just can´t fix this error till weeks... I am trying to call a function of an another class "PlayerController":
'using UnityEngine; using System.Collections;
public class PlayerJump : MonoBehaviour {
private PlayerController player;
void awake()
{
player = gameObject.GetComponentInParent<PlayerController>();
}
void OnTouchDown()
{
Debug.Log("gedrueckt");
player.playerJump();
}
void OnTouchStay()
{
Debug.Log("bleiben");
}
void OnTouchUp()
{
Debug.Log("loslassen");
}
}'
everytime OnTouchDown gets calles the error occurs.... just can´t get why? I am doing the same thing from another class and it is working, I would be very thankful if somebody could tell me what´s wrong in this code :)
Answer by dkjunior · Oct 14, 2015 at 04:51 PM
You need to capitalize Awake() function name (case matters). Also, I assume this script is attached to a child object of player controller object.
O$$anonymous$$G thanks so much... i had to put it as a child object of player controller.... u solved my error I am pondering for weeks .
Your answer
Follow this Question
Related Questions
Setting button intractability causes an error 1 Answer
Keep Getting NullReferenceException: Object reference not set to an instance of an object 0 Answers
NullReferenceException: I have no clue why I am getting this error... 0 Answers
Random Chance NullReferenceException: Object reference not set to an instance of an object 2 Answers
Array of dictionaries: "Object reference not set to an instance of an object" 0 Answers