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 Hyperactive · Mar 29, 2015 at 02:56 PM · coroutinecoroutinesienumerator

Use Coroutine when object rotates

Hi,

So I posted a question yesterday that was similar, but it lead onto a different issue. So now I'm posting this issue as a separate question.

I'm trying to make it so when my object rotates, something happens once. Which is easy. What I can't seem to figure out so far is how to revert back to the original settings after the object has stopped so that when it starts moving again, something again can happen, only once. In this case that something is the debug log "MOVING".

I'd like for the "MOVING" log to only show once for every time the object starts to move after being stationary :D

   Vector3 prevPos;
      
      public bool hasMoved = false;
  
      void Start(){
          prevPos = transform.rotation.eulerAngles;
      }
      
      void Update ()
      {
          if ((prevPos != transform.rotation.eulerAngles) && (hasMoved == false))
          {
              StartCoroutine("CheckForMove");
              hasMoved = true;
          }
          
      }
      
      
      IEnumerator CheckForMove(){
          {
              {
              Debug.Log ("MOVING");
              prevPos = transform.rotation.eulerAngles;
              yield return null;
                  }
          
      }
      
 
Comment
Add comment · Show 2
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 _joe_ · Mar 29, 2015 at 03:40 PM 0
Share

I replied to you on the other thread, there was no need to create another question.

One thing for sure: What Digital Phantom proposed is not something you would want to do (with all due respect), but instantiation is something you need to stay away from whenever possible.

Get back to me on the other thread, and like i said, i will write the code for you.

Cheers

avatar image Hyperactive · Mar 29, 2015 at 03:57 PM 0
Share

@joe Sorry for that. I wanted to separate the different issues. But indeed... a bit silly to actually make a new thread. Thanks though for all the assistants :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Digital-Phantom · Mar 29, 2015 at 03:02 PM

Once your coroutine has run just destroy the object and instantiate another in its place. (prefab of the original I mean of course)

:)

Comment
Add comment · Show 2 · 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 Hyperactive · Mar 29, 2015 at 03:07 PM 0
Share

Dude that's actually genius. I will try that. The problem I have though if I use that method in my case, is that I can't destroy this prefab. It's complicated and connected to audio ^^ Do you know a way I can achieve the same effect in the script without destroying the object ? :D

avatar image Digital-Phantom · Mar 29, 2015 at 03:27 PM 0
Share

$$anonymous$$aybe try using an empty game object. $$anonymous$$eep all the stuff you need to keep on the empty and just destroy the child(your visible object) then instantiate another prefab onto the empty object.

So basically just destroy the child, not the parent and instantiate another child.

 GameObject barrier = Instantiate(shields, other.transform.position, other.transform.rotation) as GameObject;
             barrier.transform.parent = GameObject.Find("Player").transform;
             Destroy(gameObject);
 

Use something like that to instantiate an object as a child.

$$anonymous$$ay or may not work in your case, depending on what the criteria was about stuff you need to keep, but its always worth taking a look

;)

avatar image
0

Answer by yoeyyutch · Mar 29, 2015 at 04:04 PM

My approach which may not be the most elegant but it worked, was to rotate an empty GameObject, but I wait the appropriate event occurs that initiates the rotation, before I attach the object to the parent. Once the rotation is complete, detach the child and reset the parent transform. This way you can check for these events instead of checking the actual rotation.

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

23 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

Related Questions

How do Coroutines behave with Triggers? 1 Answer

coroutine in update method 1 Answer

Coroutines not passing yield 1 Answer

Collection Change During Iteration 0 Answers

StopCoroutine with IEnumerator not working 2 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