简体   繁体   中英

“The type or namespace name could not be found. Are you missing assembly reference ?” Error in Unity

I am trying to show a GUI Label when mouse overs over an object and the label hides when mouse cursor is removed from object.

Can anyone please let me know why am i getting the error ?

using UnityEngine;
using System.Collections;

public class label_diet : MonoBehaviour {
    public showGUI boolean = false;
    void OnMouseOver()
    {
        showGUI = true;
    }

    void OnMouseExit()
    {
        showGUI = false;
    }

    void OnGUI()
    {
        if (showGUI)
        {
            GUI.Label(new Rect(10, 10, 100, 20), "You are selecting Diet coke");
        }
    }
}

Change the line that reads

public showGUI boolean = false;

To

public bool showGUI = false; //for C#
public var showGUI = false; //for JS, but you're using C#

That should work fine; if not, check that the script is attached either to a UI Object or an object with a collider component.

Please check this reference UnityEngine. If you are using dll, check dll version or check its all dependencies if include at your project.

Hope it helps..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM