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 /
This question was closed Dec 01, 2014 at 09:31 AM by Prasanna for the following reason:

Thanks to HarshadK.

avatar image
0
Question by Prasanna · Dec 01, 2014 at 06:50 AM · cameraaugmented-realitywebcamtexture

Zoom in/out Object

Hi, i have to zoom in/out my object(not camera) using pinch with min and max values.

 using UnityEngine;
 using System.Collections;
 
 public class Zoom_Button : MonoBehaviour 
 {
     private Transform Table_Transform = null;
     
     private float Scale_Factor = 0.5f;
     private bool Transform_Update = false;
     public GUITexture Zoom_In, Zoom_Out;
     
     // Use this for initialization
     void Start () {
         GameObject Table = GameObject.FindWithTag("Table");
         if (Table != null) 
         {
             Table_Transform = Table.transform;
         }
     }
     
     // Update is called once per frame
     void Update () {
         if (Transform_Update) {
             Table_Transform.localScale = 
                 new Vector3(Scale_Factor, Scale_Factor, Scale_Factor);
             Transform_Update = false;
         }
         if(Input.touchCount > 0)
         {
             if(Zoom_In.HitTest(Input.GetTouch(0).position))
             {
                 ScaleUp();
             }
             if(Zoom_Out.HitTest(Input.GetTouch(0).position))
             {
                 ScaleDown();
             }
         }
     }
     
     void OnGUI() 
     {
         Vector3 scale;
         
         float ResolutionX     = 1280;
         float ResolutionY     = 728;
         
         scale.x             = (float)Screen.width/ResolutionX;
         scale.y             = (float)Screen.height/ResolutionY;
         scale.z             = 1;
         
         Matrix4x4 svMat     = GUI.matrix;
         GUI.matrix             = Matrix4x4.TRS(new Vector3(0,0,0),Quaternion.identity,scale);
     }
     
     void ScaleUp() {
         if (Table_Transform != null) {
             Scale_Factor = Table_Transform.localScale.x;
             Scale_Factor *= 1.5f;
             
             Transform_Update = true;
         }
     }
     
     void ScaleDown() {
         if (Table_Transform != null) {
             Scale_Factor = Table_Transform.localScale.x;
             Scale_Factor *= 0.67f;
             
             Transform_Update = true;
         }
     }   
 }


Right now am using this code to zoom in/out object, yes its working with button but i have to add min and max value for my zoom in/out and importantly i need a pinch zoom. I don't know how to add those.

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 asgar · May 03, 2015 at 02:50 AM 0
Share

how to make zoom in and zoom out for augmented reality?

avatar image Prasanna · May 04, 2015 at 04:19 AM 0
Share

What you are using for augmented reality? Vuforia or some other plugins.

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by HarshadK · Dec 01, 2014 at 08:42 AM

This tutorial on PINCH TO ZOOM does all the things you want but is for camera. You just need to adapt it to work with your current object scale instead of camera FOV.

There is also script available for that tutorial under the video. :-)

Comment
Add comment · Show 10 · 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 Prasanna · Dec 01, 2014 at 08:44 AM 0
Share

@Harshad$$anonymous$$, can you please explain how to change those scale factor ins$$anonymous$$d of field of view.

avatar image HarshadK · Dec 01, 2014 at 09:11 AM 0
Share

Here's the updated script to work with scale changing:

 public float scaleFactor = 0.5f;        // The rate of change of the scale
 
 public float $$anonymous$$Scale = 0.6f;
 public float maxScale = 2.0f;
 
 void Update()
 {
     // If there are two touches on the device...
     if (Input.touchCount == 2)
     {
         // Store both touches.
         Touch touchZero = Input.GetTouch(0);
         Touch touchOne = Input.GetTouch(1);
 
         // Find the position in the previous frame of each touch.
         Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
         Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
 
         // Find the magnitude of the vector (the distance) between the touches in each frame.
         float prevTouchDelta$$anonymous$$ag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
         float touchDelta$$anonymous$$ag = (touchZero.position - touchOne.position).magnitude;
 
         // Find the difference in the distances between each frame.
         float delta$$anonymous$$agnitudeDiff = prevTouchDelta$$anonymous$$ag - touchDelta$$anonymous$$ag;
 
             // Change the scale based on the change in distance between the touches.
             Table_Trasnform.localScale.x += delta$$anonymous$$agnitudeDiff * scaleFactor;
             Table_Trasnform.localScale.y += delta$$anonymous$$agnitudeDiff * scaleFactor;
             Table_Trasnform.localScale.z += delta$$anonymous$$agnitudeDiff * scaleFactor;
 
 
             // Clamp the scale factor to make sure it's between $$anonymous$$Scale and maxScale.
             Table_Trasnform.localScale.x = $$anonymous$$athf.Clamp(Table_Trasnform.localScale.x, $$anonymous$$Scale, maxScale );
             Table_Trasnform.localScale.y = $$anonymous$$athf.Clamp(Table_Trasnform.localScale.y, $$anonymous$$Scale, maxScale );
             Table_Trasnform.localScale.z = $$anonymous$$athf.Clamp(Table_Trasnform.localScale.z, $$anonymous$$Scale, maxScale );
     }

Just get the concept and you'll be good to go.

avatar image Prasanna · Dec 01, 2014 at 09:23 AM 0
Share

Thanks for your help, i tried your code. But having some value type error. This is the error.

"Cannot modify a value type return value of `UnityEngine.Transform.localScale'. Consider storing the value in a temporary variable"

I get it, i cleared the error, and thanks for your help.

avatar image Prasanna · Dec 01, 2014 at 10:10 AM 0
Share

@Harshad$$anonymous$$, i understand your logic. But your code doesn't work for me.

avatar image HarshadK · Dec 01, 2014 at 10:22 AM 0
Share

What is happening? What behavior to you get? You also need to change the values for various variables like scaleFactor, $$anonymous$$Scale, and maxScale also.

Show more comments

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Cloud recognition in Vuforia 0 Answers

Projection mobile camera on a texture, at the same time using it as AR camera. Is it possible? 0 Answers

How to prevent image from rendering to screen but seen by camera 0 Answers

object projection from one camera to another 1 Answer

is there any tricks while navigating the scenes with the camera 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