Click on text in Canvas and go to a scene

Hi,

Big fan of Unity. I work on the art and design side. Great respect for the code side.
Thx in advance, as per below.

  • Simple Main Menu -

Trying to figure out how i can click on a specific text field in the Canvas, and have that load a specific scene.
I will have about 5 text fields that will take the player to distinct and separate scenes.

void Update ()
void Update()

Does there need to be a space between Update and ()

*Here’s what i’ve come up with, by scouring the forums.
Getting an error message:
Assets/ZFBrowser/Demo/GSmed3.cs(21,11): error CS1513: } expected

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class GSmed3 : MonoBehaviour {

void Update () {

if (Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit, 100.0f))
             {
                 //Replace this with whatever logic you want to use to validate the objects you want to click on
                 if(hit.collider.gameObject.tag == "Clickable")
                 {
                     SceneManager.LoadScene("BRxMeditation1");
                 }
             }
         }

There is no need for the space between Update and (), nor does it matter if there is one.

You’re missing a last } at the end to close the class off. Just count the number of { and } and you should have the same amount.

Thanks Brathnann.
That solved the error issue.

I’ve dropped the fixed script on the text object, and put a box collider 2D on it, and set it to trigger the script.

I’m now getting this error message:
NullReferenceException: Object reference not set to an instance of an object
GSmed5.Update () (at Assets/aaa Go Scene CPlusScriptsFolder/GSmed5.cs:12)

Any idea of what i’m doing incorrectly?
Thx.

The line that is pointing at doesn’t make sense, so I assume your script was modified. It may be that Camera.main is null. Make sure you have a camera tagged as MainCamera in your scene.

Also note you should cache the Camera.main value as it, as Camera.main basically is a GameObject.Find call.

All that being said, why didn’t you just make these buttons with an invisible image so your text showed, but the button itself doesn’t?