2
\$\begingroup\$

I'm just a beginner and I am currently having problems with the OnClick editor. I already drag and dropped my script to an empty gameobject and dragged that game object to the OnClick editor but still my function of "Pause" won't show up even if I already have it set to public. Please help

enter image description here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class uiManager : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    public void Pause() {

        if (Time.timeScale == 1) {
            Time.timeScale == 0;
        }
        else if (Time.timeScale == 0) {
            Time.timeScale == 1;
        }
    }
}
\$\endgroup\$
1
\$\begingroup\$

Based on your screenshot, you have an error in your uiManager script. The function will not appear in the inspector until you resolve this error.

The problem is in your if/else statement. You are trying to use == to assign a value to Time.timeScale. You should use the assignment operator, =, as seen below.

if (Time.timeScale == 1) 
{
    Time.timeScale = 0;
}
else if (Time.timeScale == 0)
{
    Time.timeScale = 1;
}

Once you make this correction, save the script. Then open Unity and press ctrl+s to save it. This will force the editor to update the list of functions available for OnClick().

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.