Changeing scene by clicking on a gameobject
i use this script :
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) if (hit.collider.gameObject.tag == "Planet2") Application.LoadLevel("Test0v1"); } }
and i attach to the gameobject. And nothing happend when i click on the object
Are you getting till here?? Can you try it and check whether you are getting debug logs ?
void Update()
{
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
if (hit.collider.gameObject.tag == "Planet2")
{
Debug.Log("About to load level");
Application.LoadLevel("Test0v1");
Debug.Log("Level Loaded");
}
}
}
I use your code fix every thing and still not working. Any other advice or tip?
Answer by pankajb · May 13, 2016 at 09:07 PM
If you getting console messages from above comment then use
SceneManager.LoadScene ("Test0v1");
instead of Application.LoadLevel("Test0v1");
http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html