You can use transform.rotation
like this:
transform.rotation = new Quaternion(rotx, roty, rotz, rotw);
OR
You can use transform.Rotate
like this:
transform.Rotate(rotx, roty, rotz);
Documentation for transform.rotation
Example for Rotating screen with accelerometer input:
float accelx, accely, accelz = 0; void Update () { accelx = Input.acceleration.x; accely = Input.acceleration.y; accelz = Input.acceleration.z; transform.Rotate (accelx * Time.deltaTime, accely * Time.deltaTime, accelz * Time.deltaTime); }
If you want to rotate the object to a specific angle use:
float degrees = 90; Vector3 to = new Vector3(degrees, 0, 0); transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, to, Time.deltaTime);
This will rotate 90 degrees around the x axis.
Related Posts:
- How to jump in Unity 3d?
- How to find child of a GameObject or the script attached to child GameObject via script
- Getting mouse position in unity
- How to make the script wait/sleep in a simple way in unity
- Unity OnTriggerEnter2D not registering
- OnCollisionEnter() not working in Unity3D
- Unity cannot convert from ‘string’ to ‘int’
- Can’t add script component because the script class cannot be found?
- Why should I use SerializeField?
- OnTriggerEnter not working at Unity3D
- Unity3d no Monobehaviour scripts in the file, or their names don’t match the file name
- Unity3d restart current scene
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Unity 2d jumping script
- OnCollisionEnter2D not being executed?
- Unity “The associated script can not be loaded” and “Win32Exception: The system cannot find the file specified”
- Unity – Gameobject look at mouse
- Error when Building Project: Error building Player because scripts have compile errors in the editor
- Unity3D. Trying to send command for object without authority
- Expression denotes a `type’, where a `variable’, `value’ or `method group’ was expected UNITY3D
- How to pass data (and references) between scenes in Unity
- OnCollisionEnter is not called in unity
- Unity 5.2.2 changing Visual Studio back to MonoDevelop
- “A namespace cannot directly contain members such as fields or methods”
- Unity – How to stop Play Mode in case of infinite loop?
- Unity Scripts edited in Visual studio don’t provide autocomplete
- Is there a keyboard shortcut to maximize the Game window in Unity in Play Mode?
- How to connect to database from Unity
- How can I convert String to Int?
- Process cannot access the file because it is being used by another proess
- How to convert JSON to XML or XML to JSON?
- Virustotal Trapmine suspicious.low.ml.score
- Convert int to string?
- How to Sort a List
by a property in the object - The page was not displayed because the request entity is too large on IIS
- Multiple Inheritance in C#
- Extension methods must be defined in a non-generic static class
- Return multiple values to a method caller
- Regex that accepts only numbers (0-9) and NO characters
- How to resolve this System.IO.FileNotFoundException
- Fire ontextchanged() event of an asp:TextBox via Javascript
- C# Gridview CheckBox Field VS (Template Field + CheckBox)
- Extension methods must be defined in a non-generic static class
- Convert char to int in C#
- SmtpException: Unable to read data from the transport connection: net_io_connectionclosed
- The remote server returned an error: (403) Forbidden
- How to add a delay for a 2 or 3 seconds
- Multiple file-extensions searchPattern for System.IO.Directory.GetFiles
- calling javascript function on OnClientClick event of a Submit button
- C# – Illegal characters in path
- Getting The ASCII Value of a character in a C# string
- Process exists with ExitCode 255
- The data types text and varchar are incompatible in the equal to operator in C#
- Name does not exist in the current context
- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host
- Member ‘
‘ cannot be accessed with an instance reference - Sequence contains no matching element
- The remote server returned an error: (407) Proxy Authentication Required
- when do you need .ascx files and how would you use them?
- IsNumeric function in c#
- The calling thread must be STA, because many UI components require this in WPF
- The type initializer for ‘MyClass’ threw an exception
- The server committed a protocol violation. Section=ResponseStatusLine ERROR
- Specified cast is not valid.. how to resolve this
- C# switch on type
- How to post JSON to a server using C#?
- C# Error (Cannot Implicitly convert type ‘string’ to ‘int’)
- .NET graph library around?
- EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong
- How can I cast int to enum?
- What is the C# equivalent of friend?
- How to get relative path of a file in visual studio?
- Error Message: Type or namespace definition, or end-of-file expected
- Make first letter of a string upper case (with maximum performance)
- ‘An exception occurred during a WebClient request” while using C# ASP.NET
- How to download image from URL
- Visual Studio keeps crashing
- Is there an equivalent to the Scanner class in C# for strings?
- The opposite of the modulo operator?
- How can I implement static methods on an interface?
- How to add List<> to a List<> in asp.net [duplicate]
- get path for my .exe
- The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015
- How to create a new object instance from a Type
- Cannot drop database because it is currently in use
- Troubleshooting “program does not contain a static ‘Main’ method” when it clearly does…?
- does not implement interface member
- Differences between SFTP and “FTP over SSH”
- When should I use a List vs a LinkedList
- Remove punctuation from string with Regex
- Go To Definition: “Cannot navigate to the symbol under the caret.”
- Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?
- IF Statement multiple conditions, same statement
- What is the easiest way to handle associative array in c#?
- What does the M stand for in C# Decimal literal notation?
- Iif equivalent in C#
- Convert an array to string
- is inaccessible due to its protection level
- Memory Leak caused by System.Drawing.Internal.GPStream