rotate game object via GUI

hello folks, is it posible to rotate game object via GUI? like http://www.lovemyhome.net/decorator.aspx?lang=en

is it posible? how to do that? i had search many source, but not very related to what i want, someone help me, thanks guys.

Yes it is possible and easy! Here i will let you try first and if you can not do it i will help you.

So, Here is what you need to do it.

  1. Unity - Scripting API: GUI.Button

  2. http://unity3d.com/support/documentation/ScriptReference/Transform.Rotate.html

Bikebreck

thanks for your comment, this is what i manage to do:

i able to make it rotate, but how i’m gonna make it rotate using mouse cursor,?
and how to make the GUI button stick together with the object?

thanks Bikebreck.

To do what you want to do you can not use GUI for that, you need to use function OnMouseDown. here is how you do it.

var rotateObject : Transform;
private var mouse : boolean = false; 
var Speed = 10;
function OnMouseDown () {
mouse = true;
}
function OnMouseUp () {
mouse = false;
}

function Update (){
if(mouse){
rotateObject.transform.Rotate(0, Time.deltaTime * Speed, 0, Space.World);
}

}

So, you need to attach the script to a plane with a collider on it you need to put it as a child to what you want to rotate and position it where you want it to be. Then you need to assign the rotateObject to what you want to rotate.

i attach the unity package for it.

Here is the OnMouseDown docs http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDown.html

bikebreck

666558–23890–$Rotatehelp.unitypackage (4.96 KB)

thanks Bikebreck, it gave me some idea on how to do it, thanks again.

i’ll post my script to you if i manage to do what i want, thanks again man.

this is what i manage to do so far,

problems:

  1. how to make the “arrow” appear only when i click the object that have this script.

  2. i get this error ; NullReferenceException

i had attach some image :

== the image that has arrow around it is what i want==

== the image without arrow around it is what i mange to get so far ===

please help me :expressionless:
thanks a lot.

668297–23970–$print.bmp (1.4 MB)
668297–23971–$print2.bmp (1.35 MB)

you can do all this in your script. create a plane, place the arrow texture png on it, make sure it is scaled as you need it to be, then in the OnMouseDown() add an Instantiate(), make sure that OnMouseUp() you destroy that object.

thanks ar0nax,
i’ve manage to do what u said, but, how to limit the number of clone? because when i click on the game object, it’s keep on cloning the arow.

easyest way is to set a boolean variable, and change it’s value once you instantiate, also make sure before instantiating you check that booleans value.

this is what i have now, how to set the boolean variable? sory, i.m not very good in scripting.

before you Instantiate your plane place this:

if(!mouse){
	rotateObject = Instantiate(ring, transform.position, transform.rotation);
	mouse = true;
}

this way it will only instantiate one object;

thanks man, it’s working :slight_smile:

no problem mate!

i manage to get the arrow appear when i click on the game object, but why does i can only rotate the arrow, but the game object didn’t rotate together with the arrow?

this is my script, thanks guys.!

it’s solved!

this my script:

congrats!