Hello,I got a problem in my script. But actually I don’t even know what I did wrong. I hope you can help me out.
This script should find the gameobject and disable or enable the “BoxCollider2D” of it.
I did this so that the boxcolliders wouldn’t overlay eachother.
The first 5 objects you see in the script have their boxcollider2D disabled, and have yet to be enabled. This happens when you click on the Collider where this script has been assigned to.
This is the error i get :
NullReferenceException: Object reference not set to an instance of an object
OnStart3.OnMouseDown () (at Assets/OnStart3.js:4)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)
function OnMouseDown() {
Debug.Log("click");
GameObject.Find("back2home").GetComponent(BoxCollider2D).enabled=true;
GameObject.Find("world1").GetComponent(BoxCollider2D).enabled=true;
GameObject.Find("world2").GetComponent(BoxCollider2D).enabled=true;
GameObject.Find("world3").GetComponent(BoxCollider2D).enabled=true;
GameObject.Find("world4").GetComponent(BoxCollider2D).enabled=true;
GameObject.Find("Beginscreen").GetCompenent(SpriteRenderer).enabled=false;
GameObject.Find("Optionmenu").GetComponent(BoxCollider2D).enabled=false;
GameObject.Find("ToStart").GetComponent(BoxCollider2D).enabled=false;
GameObject.Find("Twitterredirect").GetComponent(BoxCollider2D).enabled=false;
}
Thanks for reading. I hope you can help me out.
EDIT : Fixed the problem. There is nothing wrong with the script. Rather Unity is being weird as always. Seems like the problem fixed itself (thanks for all the help)