- Home /
Question by
sethbearz · Apr 19, 2012 at 05:31 PM ·
c#nullreferenceexceptiongetcomponent
NullReferenceException with GetComponent() C#
public class PlayerSprite : MonoBehaviour
{
protected ScrollControl scrollScript;
void start()
{
scrollScript = gameObject.GetComponent<ScrollControl>();
//scrollScript = gameObject.GetComponent("ScrollControl") as ScrollControl;
scrollScripte.enabled = false;
}
}
I'm having NullReferenceException error during runtime for scrollScript.enabled = false;
I've tried the both ways of initializing scrollScript
but to no avail. Can someone help me T.T
Comment
Your answer

Follow this Question
Related Questions
Object reference not set to an instance of an object in c#. 0 Answers
Has my project's data corrupted? Script keeps returning null but 20 minutes ago it wasn't? 1 Answer
I'm having more problems accessing a variable from another script in c# 2 Answers
NullReferenceException when trying to access other GO in script. C# 1 Answer
Multiple Cars not working 1 Answer