- Home /
NullReferenceException: Object reference not set to an instance of an object
Help! I want to add 1 point to script A from script B but an error pops up(refer to title). I don't know what's wrong with it.
!!! movto2tama is the name of the script B.
Script A:
public var pluspoints : movto2tama;
function Update()
{
pluspoints.APoint();
}
Script B:
private var points : int = 0;
function APoint()
{
points = points + 1;
print(points);
}
Thanks!
Comment
Answer by robertbu · Feb 18, 2013 at 06:18 PM
Likely 'movtotama' has not be assigned. You an drag the object that contains Script B onto the movto2tama variable in the inspector to do a link. Or you could setup the variable in Start(). Something like:
Start()
{
movto2tama = GameObject.Find("NameOfGameObjectContainingScriptB");
}