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
- Convert HTML to PDF in .NET
- How to show a loading gif while an APi is being called in xamarin android?
- ImageMagick creating blank transparent square(s) according to width
- .Net 4.8 Support for Windows 10 ends in 26 days?
- How do I generate a random int number?
- Why has the int32 type a maximum value of 2³¹ − 1? [duplicate]
- What is a NullReferenceException, and how do I fix it?
- How do I get a random YouTube video with the YouTube API?
- An existing connection was forcibly closed by the remote host
- C# HttpClient An existing connection was forcibly closed by the remote host
- How can I convert String to Int?
- What is a NullReferenceException, and how do I fix it?
- What is a PDB file?
- What is the { get; set; } syntax in C#?
- Unexplained crashes related to ntdll.dll
- I am getting Failed to load resource: net::ERR_BLOCKED_BY_CLIENT with Google chrome
- How can I parse JSON with C#?
- Can anyone explain IEnumerable and IEnumerator to me? [closed]
- What is parsing?
- What is IP address ‘::1’?
- CS0120: An object reference is required for the nonstatic field, method, or property ‘foo’
- IOException: The process cannot access the file ‘file path’ because it is being used by another process
- Process cannot access the file because it is being used by another proess
- Error : Index was outside the bounds of the array.
- How to fix “HTTP Error 400. The size of the request headers is too long” error from azure cloud services?
- C# error: “An object reference is required for the non-static field, method, or property”
- No connection could be made because the target machine actively refused it?
- How to convert JSON to XML or XML to JSON?
- Virustotal Trapmine suspicious.low.ml.score
- What is the difference between declarative and imperative paradigm in programming?
- How to fix No connection could be made because the target machine actively refused it 127.0.0.1:64527
- Could not load file or assembly or one of its dependencies
- What does a lock statement do under the hood?
- What is the yield keyword used for in C#?
- Error : Could not load file or assembly or one of it’s dependencies
- Group by in LINQ
- Join/Where with LINQ and Lambda
- Convert int to string?
- Converting string to byte array in C#
- Could not load file or assembly or one of its dependencies
- All possible array initialization syntaxes
- Adding values to a C# array
- C# compiler error: “not all code paths return a value”
- What is C# equivalent of
- How to use SQLite in Visual Studio 2017?
- Algorithms in O(n^2) vs O(n) [duplicate]
- LINQ’s Distinct() on a particular property
- What are the benefits to marking a field as `readonly` in C#?
- Priority queue in .Net
- How to Sort a List
by a property in the object - What is the difference between int, Int16, Int32 and Int64?
- How to resolve “Input string was not in a correct format.” error?
- failed to load resource: the server response with a status 500 (internal server error)
- Adding values to a C# array
- C# compiler error: “not all code paths return a value”
- How can I add ” character to a multi line string declaration in C#?
- C# equivalent of C++ map
- Input string was not in a correct format
- The request was aborted: Could not create SSL/TLS secure channel
- C# 2D platformer movement code
- How to convert byte array to string [duplicate]
- C# Java HashMap equivalent
- The remote certificate is invalid according to the validation procedure [duplicate]
- The page was not displayed because the request entity is too large on IIS
- The page was not displayed because the request entity is too large on IIS
- ASP.NET 5 MVC: unable to connect to web server ‘IIS Express’
- What is the purpose of nameof?
- Configuration System Failed to Initialize
- Converting a String to DateTime
- C# An established connection was aborted by the software in your host machine
- Difference between virtual and abstract methods