Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KiksRo · Feb 26, 2021 at 08:32 PM · euler angles

rotate game object with eurle angles ,

im trying to rotate my game object with eurle angles and get more tha 1 position using only one getkey for my video game

if (Input.GetKey(KeyCode.RightArrow)) {

        GetComponent<Transform>().eulerAngles = new Vector3(0, 110, 0);
        FindObjectOfType<audioManager>().play("slide");


     } 

im try to rotate this other positions (0,250,0)

(0,360,0)

(0,630,0)

using only one Input.GetKey(KeyCode.RightArrow)),im triying to use euler angles to rotate my game object using only one getkey and try to get more than one position in the same getkey

if (Input.GetKey(KeyCode.RightArrow)) {

        GetComponent<Transform>().eulerAngles = new Vector3(0, 110, 0);
        FindObjectOfType<audioManager>().play("slide");

     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SoshJam · Feb 27, 2021 at 12:06 AM

First of all, replace GetComponent<Transform>() with transform. The transform variable is public, and automatically assigned to all GameObjects, so manually retrieving it every time will just hurt performance and give you a headache.

If you use your AudioManager multiple times in this script, you should also assign it to a variable at the beginning, so that you don't have to search for it again every time you want to use it.

Now to solve your problem: Use if statements to check which position it should be rotating to. I assume you have a variable that you would use to check which position you need to rotate to next.

 if (nextPosition == 1)
 {
     transform.eulerAngles = new Vector3(0, 110, 0);
 }
 else if (nextPosition == 2)
 {
     transform.eulerAngles = new Vector3(0, 250, 0);
 }
 // Continue this If/Else block for all positions.

Alternatively, if your positions were all equal rotations apart (like 90, 180, 270, 360) you could simply call transform.Rotate(0,90,0); instead of needing a whole variable.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Euler angle problems with rotation limit script 3 Answers

Get local euler angles by Quaternion 1 Answer

Getting the velocity direction as a euler angle. 2 Answers

,How to clamp my turret rotation? 1 Answer

Why is rotation locking to an axis? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges