- Home /
NullReferenceException
void OnTriggerEnter2D(Collider2D col){
Vector3 pos = col.transform.position;
Set set = GetComponent<Set>();
pos.y += 28;
col.transform.position = pos;
if(col.name == ("Platform1")){
set.Set1();
}else if(col.name == ("Platform2")){
set.Set2();
}else if(col.name == ("Platform3")){
set.Set3();
}else if(col.name == ("Platform4")){
set.Set4();
}else if(col.name == ("Platform5")){
set.Set5();
}else if(col.name == ("Platform6")){
set.Set6();
}else if(col.name == ("Platform7")){
set.Set7();
}
}
nullreferenceexception - set.Set1;
Don't know why.
I am a noob.
Sorry.
Thanks.
Answer by Ed unity · May 05, 2014 at 03:56 PM
You cannot use the lowercase set as a variable name in C#.
It is a C# reference: http://msdn.microsoft.com/en-us/library/ms228368.aspx
Name your variable something like TriggerSet and then change all of the uses of it in code to the same.
Your answer
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object ..... 1 Answer
GetComponent, Object Reference not set to an instance of an object 0 Answers
InitializeOnLoad = System.NullReferenceException 1 Answer
Assign collider and linerenderer to list 1 Answer
The infamous: Object Reference not set to an instance of an object 1 Answer