Unity 2019 can't change/access GameObject Variables from another script
Hello guys ! I'M just starting with Unity, I was following a tutorial but using my own sprites. I have no idea why there is an error . I don't know how something so simple is not working. " NullReferenceException: Object reference not set to an instance of an object PurpleMaster.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/PurpleMaster.cs:21)""
when it gets triggered the score1 doesnt go up.
While trying to debug, i realised that the OnTriggerEnter2D method is working and the object gets destroyed. Though, anything to do with my GameObject.GoblinDroite doesnt seem to work and be linked to my script... I've been looking for a solution for days.
Thanks so much for your help i need it !
script:
public class PurpleMaster : MonoBehaviour { public GoblinDroite Goblin;
private void Start()
{
Goblin = GameObject.Find("GoblinDroite").GetComponent<GoblinDroite>();
}
private void OnTriggerEnter2D(Collider2D other)
{
GameObject.Destroy(gameObject, 0);
Goblin.score1++;
Goblin.scoreText.text = Goblin.score1.ToString();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613013335im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check GameObject rotation in Y axis when OnTriggerEnter 1 Answer
How to make scoring system 1 Answer
Trigger Sets GameObject 0 Answers
Reset GameObject with trigger on respawn 1 Answer
My gameobject stops moving after entering the trigger?? 2 Answers