Question by
finalsin · Dec 25, 2015 at 11:21 PM ·
scripting problem
NullReferenceException using GetComponent<>()
I don't quite understand why i keep receiving a NullReferenceException when using the code in script "ClickableObject"
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ClickableObject : MonoBehaviour, IPointerClickHandler
{
_GameControler gc;
void start()
{
gc = GetComponent<_GameControler>();
}
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
Transform currentChild = eventData.selectedObject.transform.GetChild(0);
gc.ChangeButtonText(int.Parse(currentChild.name));
}
}
}
To access the function in script "_GameControler"
public void ChangeButtonText(int index)
{
Debug.Log(index);
}
Both Scripts are attached to an empty GameObject in the editor
and running the script and activating the trigger for OnPointerClick returns this error
Can anyone tell me how I'm being dumb?
capture2.png
(111.3 kB)
capture3.png
(32.2 kB)
Comment
Answer by Wolv15 · Dec 26, 2015 at 11:00 AM
void Start() not void start() ;)
Sadly that wasn't the only problem, thanks for helping tho!
Your answer
