Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 areFranz · Oct 28, 2017 at 08:43 AM · cameracoroutinemovezoom

Move camera on the z axis forward and backward with coroutine

Hi, I'm making a simulation of a desktop in a 3d space, and I need to move the main camera along the z axis forward when I am over a 3d icon and backward when I left the icon with the mouse. Here is my code but the coroutines can't work together in the way I need:

     IEnumerator Zoom (float zPos, float delay)
     {
         yield return new WaitForSeconds (delay);
 
         float elapsedTime = 0.0f;
 
         while (elapsedTime < 2.0f) {
             elapsedTime += Time.deltaTime;
             Camera.main.GetComponent<FreeMovement> ().zPos = Mathf.Lerp (Camera.main.transform.position.z, zPos, elapsedTime / 2.0f);
             yield return null;
         }
     }

And I call the coroutine here:

 void OnMouseEnter ()
 {
     StartCoroutine (Zoom (50.0f, 0.0f));
 }

 void OnMouseExit ()
 {
     StartCoroutine (Zoom (0.0f, 2.0f));
 }

The script is attached to every icon in the space, the zPos is controlled over the FreeMovement script attached to the main camera.

The result is that zooming in is ok but zooming out takes place for the next zoom in. I've tried to add a delay but what I really need is a coroutine that results in zooming in while mouse enter and zooming out from the last position on mouse exit towards 0 without jumps. Is it possible?

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 MezFo · Oct 28, 2017 at 03:47 PM 0
Share

So when you put your mouse over icon it zooms but does not zoom out until your mouse is over a different icon, even if you wait 2 seconds before hovering over next icon? If that is the problem then it is most likely something to do with the script that is responsible for checking when you are and when you are not hovering over an icon.

avatar image areFranz MezFo · Oct 29, 2017 at 12:25 PM 0
Share

No, when I put the mouse on an icon, it zooms in and if I exit the icon it zooms out only if I wait 2 seconds... but I need that if I exit from the icon, the camera moves backward from the actual position.

0 Replies

· Add your reply
  • Sort: 

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

114 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 avatar image avatar image

Related Questions

Issue With Simultaneous ReadPixels Calls 0 Answers

Orbit Camera Zoom limit 1 Answer

How to get a camera state to wait with coroutine? 0 Answers

CharacterController.move is jerky in coroutine 1 Answer

Zoom in on object and make other objects disappear on zoom?,Zoom in on object and make other objects disappear 0 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