how to make it so when you click on a gameobject it changes scenes

I want to make a point and click game, and the way it’ll work (no idea how to do it any other ways) Is you’ll click on arrows and then it’ll send you to another scene. what I’ve tried so far: I’m

i

f ( Input.GetMouseButtonDown (0)){ 
        RaycastHit hit; 
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
       if(hit.transform == gameObject) //replace gameobject with the GameObject you want
     {
     //load your scene here
     }   
     }
      }

I have also used this:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;


public class cpWarpHouse : MonoBehaviour
{
	public string sceneName;
	void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			SceneManager.LoadScene("Scene2);
		}


	}
}

1 Answer

1

Most point and click games work on the same scene, they just move around different levels through toggling a group of gameobjects, it will be easier.
Although if you want to make that object load a scene you can use this.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
 
 
public class GoToScene: MonoBehaviour
{
    public string sceneName;

    void OnMouseDown()
    {
         SceneManager.LoadScene(sceneName);
    }
     
}