- Home /
GUI Toggle and rotation???
Hello all,
i am a newbie in this Unity awesomeness... i have this simple code to rotate a given game object:
function Update() { transform.Rotate(0, 20 * Time.deltaTime, 0); }
it works quite well, just the way i want it to happen. however i couldnt figure out how to connect GUIToggle button with this code. what i mean is, when i toggle the GUIToggle button on, the cube starts to rotate, when untoggle it stops...
is there ay way to do this with using the Gui Toggle button?
Answer by IJM · Oct 19, 2010 at 12:06 PM
using UnityEngine; using System.Collections;
public class rotate : MonoBehaviour { private bool _rotation;
void Update()
{
if(_rotation)
transform.Rotate(0, 20 * Time.deltaTime, 0);
}
void OnGUI()
{
_rotation = GUI.Toggle(new Rect(10, 10, 100, 30), _rotation, "Rotation");
}
}
Assets/rotate.cs(1,23): error CS0246: The type or namespace name `$$anonymous$$onoBehaviour' could not be found. Are you missing a using directive or an assembly reference?
i am having this error, is there any possible reason why?
Yes, this code is C# and you are trying to use it as a JavaScript...
Actually, it's probably because there's no 'using' directive and $$anonymous$$onoBehaviour is unqualified.
sry. I didn't see rotate.cs; You need to add using UnityEngine; using System.Collections; on the top of this script, before public class rotate : $$anonymous$$onoBehaviour
I mada an edito on my answer, copy this new code and it will work.
Your answer

Follow this Question
Related Questions
Toggle Enabled/Disabled script? 2 Answers
Mouse Problem 2 Answers
How to change camera when mouse button is clicked? 2 Answers