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 Selenor · Jul 02, 2015 at 05:02 AM · rotatewaitforsecondsnew user

Rotate to an amount, wait, rotate to an amount

I'm making an obstacle course and I need a platform to rotate along the Z axis to 60 degrees, wait 3 seconds, rotate to -60 degrees and then loop. I'm really new to unity, this is my first project and I've been stuck on this for a while. I thought of using an if statement but I don't know how to correctly set it up, something that would be like:

Continue to increase z axis rotation by 1
If z axis rotation = 60
Wait 3 seconds
Start to decrease rotation by 1
If z axis rotation = -60
Loop

But I have no idea how to go about doing this. I also tried using Coroutines for the wait but that just messed up the code more. If someone could show me how to get this to work it would help me a ton
Thanks!

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 NeverHopeless · Jul 02, 2015 at 05:47 AM

As I see you have two more options:

  1. Animator Component

  2. LeanTween plugin.

With first option you can define two state animation Rotate and Stop. Use InvokeReperating to toggle the states every 3 seconds. e.g.,

 GetComponent<Animator>().SetInt("yourStateVariable", yourStateNumber);

With second option you can use:

 void RotateZ() {
     LeanTween.rotateZ(this.gameObject, -60.0, 0.5f);
 }

and use InvokeRepeating to schedule this function for every 3 seconds. e.g.,

 InvokeRepeating("RotateZ", 0.1f, 3.0f);

Comment
Add comment · Show 3 · 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
avatar image Selenor · Jul 02, 2015 at 05:20 PM 0
Share

Ok so right now I installed and imported LeanTween and my code looks like:

 void Start()
 {
     InvokeRepeating ("RotateZ", 0.1f, 3);
 }


 void RotateZ() {
     LeanTween.rotateZ(this.gameObject, -60.0, 0.5f);
 }

}

But I'm currently getting two errors:
1.) The best overloaded match for 'LeanTween.rotateZ(UnityEngine.GameObject,float, float)' has some invalid arguments 2.)Argument '#2' cannot convert double expression to type 'float'

avatar image NeverHopeless · Jul 02, 2015 at 09:47 PM 0
Share

InvokeRepeating ("RotateZ", 0.1f, 3f); Here just 3 means 3(double) you need to specify it be considered as float using 3f.

avatar image Selenor · Jul 12, 2015 at 03:32 AM 0
Share

Alright thanks man that works!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

LookAt inaccurate rotation issue (javascript) 1 Answer

How to make a game charachter rotate towards you when close enough? 1 Answer

Camera under Camera not fully rorating (FPS Controller) 0 Answers

How to enable the mouse cursor in some areas? 1 Answer


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