please can someone help me debugging this C# script? :-(

I’m new in unity,this is my C# script:

using UnityEngine;
using System.Collections;

public class stopmenu : MonoBehaviour {

private int controllomenu;

void Update () {
if (GameObject.Find(“controllotasti”).GetComponent.controllomenu == 0)
{

}
}
}

this script give me this error

Error CS0119 ‘GameObject.GetComponent()’ is a method, which is not valid in the given context

Please use tags when you post your work to the forums.
If you’re unsure how to do this, there is a pinned/stickied thread that explains it.

There are several issues with your code. You might want to try looking at some of the starting tutorials here in unity (maybe for scripting and later on whatever else you’re doing if you’re stuck).

GetComponent().controllomenu == 0;

is how you would do it.
However, you would not want to be using GameObject.Find in update (or at all, look for other alternatives).
Plus, unless you have a variable by the same name in both files (which is okay/no problem), there could be something amiss with having controllomenu in the file as is…

Anyhow, if you just wanted the " () " after … you’re all set! =)

1 Like

ok,thank you :slight_smile:
it works!!! :slight_smile:

how must I do to stop the player by moving when the menu is opened?

void Update () {
       if (GameObject.Find("controllotasti").GetComponent<esc>().controllomenu == 0)
        {
           //stop moving
        }
        else
        {
            //you can move...
        }

}

Thanks in advance

Please help me again

Post your scripts using the code tags and you’ll get help more easily: http://forum.unity3d.com/threads/using-code-tags-properly.143875/

1 Like

ok