I need help figuring out how to change a variable from another object.
I have one object named Player that has a public float named “size”, and I have a second object named.…Circle that I want to be able to increase size from, but I can’t. This is my code in Circle:
Code (CSharp):
- void OnCollisionEnter2D(Collision2D coll)
- {
- if (coll.gameObject.name == “Player”)
- {
- this.GetComponent().size += 1;
- }
- }
Whenever I run this code I get a nullreferenceexception error. I am very new to Unity and C#, so please explain it to me like I have no idea what code even is.