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 04, 2014 at 05:57 AM by Prasanna for the following reason:

Make Table_Transform as public and assign that in inspector window.

avatar image
0
Question by Prasanna · Dec 02, 2014 at 04:38 AM · camerascalepinch

Pinch not working

Hi, i have code for scale my objects using pinch. But it's not working, can anyone tell me please?

 using UnityEngine;
 using System.Collections;
 
 public class Zoom_Button : MonoBehaviour 
 {
     private Transform Table_Transform = null;
     
     public float scaleFactor = 0.5f;        // The rate of change of the scale
     
     public float minScale = 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 prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
             float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
             
             // Find the difference in the distances between each frame.
             float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
             
             Table_Transform.localScale += new Vector3(deltaMagnitudeDiff * scaleFactor, deltaMagnitudeDiff * scaleFactor, deltaMagnitudeDiff * scaleFactor); 
             
             float Table_X, Table_Y, Table_Z;
             
             Table_X = Mathf.Clamp(Table_Transform.localScale.x, minScale, maxScale);
             Table_Y = Mathf.Clamp(Table_Transform.localScale.y, minScale, maxScale);
             Table_Z = Mathf.Clamp(Table_Transform.localScale.z, minScale, maxScale);
             
             Table_Transform.localScale = new Vector3(Table_X, Table_Y, Table_Z);
         } 
     }
 }

This is the code. Here it didn't show any errors.

-Prasanna

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 yashpal · Dec 02, 2014 at 06:26 AM 0
Share

@Prasanna, I didn't test your code but I think you not assign Table_Transform = null . and you didn't need to scale up and down your object you can use camera for that here is example of that.

avatar image Prasanna · Dec 02, 2014 at 06:37 AM 0
Share

@yashpal, actually am using webcamtexture for my project, so if am use to pinch the camera my whole camera(view) is zoo$$anonymous$$g. But i want to zoom only the objects, that's why i choose this way to zoom.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by HarshadK · Dec 02, 2014 at 06:46 AM

You need to assign a transform to your Table_Transform variable otherwise it will be null always. Just assign your transform of your intended object in Start() to your Table_Transform variable.

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

Follow this Question

Answers Answers and Comments

26 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

Related Questions

A node in a childnode? 1 Answer

Accurate Pinch Zoom 1 Answer

Math behind Unity camera model 0 Answers

Blender and Unity Camera Setup 1 Answer

Make long distance objects visible on camera 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