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 lemiwinks · Nov 03, 2013 at 10:09 PM · sizezoom

zooming camera out then back in

hey all, im creating a feature so at the start of the level the camera zooms out to show the map then zooms back in. so far my camera zooms out however when its coded to zoom back in, it does nothing, it just stops zooming altogether. its orthographic btw so im changing size. im using camera.orthographicSize += Time.deltaTime * speedZoom; to zoom out and zooming in by swicthing the - to a +.

heres my full script

 using UnityEngine;
 
 using System.Collections;
 
  
 
 public class IsometricCamera : MonoBehaviour
 
 {
 
     private GameObject target;
     
     public GameObject TargettoBall;
     
     public float speedZoom = 9;
 
     public float size = 10;
     private float EndZoom = 15;
 
     public float scrollSpeed = 30;
     private float maxPos = 9;
     private bool StartLevelMove = true;
     private bool Zoomedout = false;
     
     // zoom in-out buttons
     public GUITexture ZoomIN;
     public GUITexture ZoomOUT;
     //public Texture2D ZoomIN;
     //public Texture2D ZoomOUT;
 
 
     private Camera cam;
 
  
     
     void Start()
 
     {
 
         this.cam = (Camera)this.gameObject.GetComponent("Camera");
 
         this.cam.isOrthoGraphic = true;
 
         this.cam.transform.rotation = Quaternion.Euler(42, 36, 359); 
         
         this.cam.orthographicSize = 9;
         
         target = TargettoBall; 
         
         StartCoroutine(Changecam());
         
         speedZoom = 9;
 
     }
 
      void Update()
 {
         
         
         
     if (Input.GetMouseButtonDown(0))
     {
         if (ZoomIN.HitTest(Input.mousePosition))
         {
          if (this.cam.orthographicSize >=6)
             this.cam.orthographicSize -= 2;
             Debug.Log (this.cam.orthographicSize);
             //ZoomIn();
         }
         if (ZoomOUT.HitTest(Input.mousePosition))
         {
             if (this.cam.orthographicSize <=14)
                 this.cam.orthographicSize += 2;    
                 Debug.Log (this.cam.orthographicSize);
                 
             
             //ZoomOut();
         }
     }
         
     if (StartLevelMove == true)
         {
             camera.orthographicSize += Time.deltaTime * speedZoom;
             
         
         }
             
 //}
 //    void LateUpdate()
 //
 //    {
 
         //this.cam.orthographicSize -= Input.GetAxis("Mouse ScrollWheel") * scrollSpeed * Time.deltaTime;
 
 
         float distance = 30;
 
 
          var go = target.gameObject;
         if (go == null)
         {
           
         }
         else 
         {
         transform.position = Vector3.Lerp(transform.position, target.transform.position + new Vector3(-distance, distance, -distance), 2.0f * Time.deltaTime);
 
         this.cam.transform.LookAt(target.transform);
         }
         
         if (camera.orthographicSize <= maxPos)
             speedZoom = 0;
         Debug.Log (speedZoom);
     }
     
     IEnumerator Changecam()
 {
     yield return new WaitForSeconds(2.5f);
     camera.orthographicSize -= Time.deltaTime * speedZoom;
     StartLevelMove = false;
     
     //speedZoom = 9;
     //this.cam.orthographicSize = 9;
 }
 
  
 
     
 
 }
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 Freaking-Pingo · Nov 03, 2013 at 10:25 PM

After 2.5 seconds, your code executes the remaining part of the coroutine. The problem is, this is only executed once because you don't have any loops An example could be:

 IEnumerator Changecam()
 {
     yield return new WaitForSeconds(2.5f);
     StartLevelMove = false;
     while(camera.orthographicSize > 6){
        camera.orthographicSize -= Time.deltaTime * speedZoom;
        yield return null;
     }
 }

Remember to save your project when playing with while loops :)

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 lemiwinks · Nov 03, 2013 at 10:27 PM 0
Share

yeah sorry about the mess =S

line 24, i set call and set it to true, it zooms out fine when it starts, its getting it to zoom back in where the problem is

avatar image Freaking-Pingo · Nov 03, 2013 at 10:33 PM 0
Share

Ahh sorry, hold on I know what the problem is then, I'll edit my answer

avatar image lemiwinks · Nov 03, 2013 at 11:04 PM 0
Share

hmmm, nope still doesnt make it start zoo$$anonymous$$g, i think your right with nthe fact its not in update though, ill try a few things

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

16 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

Related Questions

Multiple Cars not working 1 Answer

How to add Elements? Multiple ones!????? Help PLease 1 Answer

C# Changing GUI font size 0 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

How big of a project is TOO big? (typically) 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