I need help with error code: CS0234
Hi! I'm following a tutorial (at 5:45 to 7:46) at a game example. Right now im doing the UI. In my version of unity there dosen't seem be an element/object called UI in the heirarchy, but there is one called GUI and they seem to be/look alike.
My Code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Boll_kontroll : MonoBehaviour {
public float speed;
public Text countText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up")) {
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "count: " + count.ToString ();
}
}
Im getting the error code at the second line in the code, "using UnityEngine.UI;". It says "The type or namespace name 'UI' does not exist in the namespace 'UnitityEngine'".
I have tried to replace the '.Ui' in 'UnityEngine' with '.GUI' because i use GUI instead of Ui, that didn't work.
Thanks in before hand and sorry for my broken english.
What version of Unity are you using?
If you're using a version prior to 4.6 the Namespace UnityEngine.UI didn't exist whatsoever, the old system which relied on the OnGUI method was what was in place, that has been deprecated and replaced with the UnityEngine.UI namespace and a completely different methodology of UI development within the Editor.
If you're using less than 4.6, you can not "FIX" this error unless you update your version of unity to a supporting version.
Answer by Cynikal · Nov 03, 2016 at 12:01 PM
This is a bug. FYI: UI is correct. Not GUI.
You can try: Right Clicking in your Project Folder View, and Reimport All.
You can also (depending on what IDE you're using (MonoDevelop or VS)) you can Sync the project, or delete the "Library" folder from your MAIN Project folder (Up a level from your Assets folder) and let it rebuild.