Hello everyone!
I’m working on switching scenes in my project. I would like to do so by clicking one of my objects placed in the scene.
My object has Rigidbody2D and a 2D Box Collider. It also has a child that changes the sprite when moused over.
I have tried to use this code:
function Update () {
if(Input.GetMouseButton(0))
Application.LoadLevel("NextLevel");
}
But then when I click anywhere on the scene it will change and not by clicking the specific object.
I also tried to use Ray casting by using this code:
void Update(){
if (Input.GetMouseButtonDown(0)){ // if left button pressed...
Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)){
Application.LoadLevel("NextLevel");
}
}
}
But that doesn’t do anything at all.
I’m very new to Unity.
Thank you very much in advance for looking at this!