Willi Gooden
Willi Gooden

Reputation: 21

How to rotate a game object in runtime in unity

How can I rotate something in unity in runtime?

I tried:

transform.rotation = Quaternion.Euler(new Vector3(x,y,z));

,

transform.Rotate(x,y,z);

,

transform.eulerAngles = new Vector3(x,y,z)

Nothing I tried worked.

Upvotes: 0

Views: 14850

Answers (3)

see
see

Reputation: 1

If you want to rotate to a certain position, I recommend using:

transform.rotation = Quaternion.Euler(Vector3.forward * degrees);

Upvotes: 0

Cardstdani
Cardstdani

Reputation: 5223

To rotate a GameObject in Unity, the best way is using the Rotate function:

public float speed = 20f

public void Update()
{
    transform.Rotate(Vector3.right * speed * Time.deltaTime);
}

With this code, your GameObject will rotate to the right, you can use Vector3.up or Vector3.forward.

If you only want to set a new rotation for your GameObject, change the localEulerAngles of the transform component:

transform.localEulerAngles = new Vector3(x, y, z);

Upvotes: 2

Ankity
Ankity

Reputation: 13

transform.Rotate (new Vector3 (0, 0, 45) * Time.deltaTime);

Visit this site, it will help you https://learn.unity.com/tutorial/collectable-objects#

sorry if I am wrong

Upvotes: 1

Related Questions