rotate around x axis unity code example

Example 1: rotation around own axis in unity

transform.RotateAround(transform.position, transform.up, Time.deltaTime * 90f);

Example 2: unity rotate around axis

transform.Rotate(axis, degrees);

Example 3: unity rotate object c#

using UnityEngine;// Transform.Rotate example
//
// This script creates two different cubes: one red which is rotated using Space.Self; one green which is rotated using Space.World.
// Add it onto any GameObject in a scene and hit play to see it run. The rotation is controlled using xAngle, yAngle and zAngle, modifiable on the inspector.public class ExampleScript : MonoBehaviour
{
    public float xAngle, yAngle, zAngle;    private GameObject cube1, cube2;    void Awake()
    {
        cube1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube1.transform.position = new Vector3(0.75f, 0.0f, 0.0f);
        cube1.transform.Rotate(90.0f, 0.0f, 0.0f, Space.Self);
        cube1.GetComponent<Renderer>().material.color = Color.red;
        cube1.name = "Self";        cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube2.transform.position = new Vector3(-0.75f, 0.0f, 0.0f);
        cube2.transform.Rotate(90.0f, 0.0f, 0.0f, Space.World);
        cube2.GetComponent<Renderer>().material.color = Color.green;
        cube2.name = "World";
    }    void Update()
    {
        cube1.transform.Rotate(xAngle, yAngle, zAngle, Space.Self);
        cube2.transform.Rotate(xAngle, yAngle, zAngle, Space.World);
    }
}

Example 4: unity rotate quaternion around axis

RoatationVar = Quaternion.Euler(Vector3.up) * camera.rotation;

Example 5: touch unity rotate on x axis

#pragma strict    private var h : float;  private var v : float;  private var horozontalSpeed : float = 1.0;  private var verticalSpeed : float = 1.0;    function Update()  {      if (Input.touchCount == 1)      {          var touch : Touch = Input.GetTouch(0);                    if (touch.phase == TouchPhase.Moved)          {              var v : float = verticalSpeed * touch.deltaPosition.x ;          transform.Rotate ( h, 0, 0);                    var h : float = horozontalSpeed * touch.deltaPosition.y ;          transform.Rotate (0, -v, 0);          }     }       }