Gasric
January 28, 2019, 3:44pm
1
Hi Folks,
Please can you take a look at my code and tell me what im missing please? I am trying to call an object from another script but it returns null ref.
Scrip1 that holds public int.
public class PointsScript : MonoBehaviour
{
public int point = 2;
}
Script2 trying to call the int.
public class Controller : MonoBehaviour
{
void Start(){
pointsScript = GameObject.Find("PointScript").GetComponent<PointScript>();
}
void Scoring(){
scoreBoard.text = pointScript.point.ToString();
}
Thanks
That means that either GameObject.Find didn’t find anything or GetComponent didn’t find anything, depending on which line the error is occuring. Check your spelling, maybe? I notice that in your listings, sometimes you are writing 'PointScript" and sometimes you are writing “PointsScript”
1 Like
Gasric
January 28, 2019, 7:00pm
3
kdgalla:
That means that either GameObject.Find didn’t find anything or GetComponent didn’t find anything, depending on which line the error is occuring. Check your spelling, maybe? I notice that in your listings, sometimes you are writing 'PointScript" and sometimes you are writing “PointsScript”
yeah it wasn’t finding the object but it was a odd one as i restarted unity and it found it. Thanks for help.