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 freeride474 · Jul 25, 2012 at 10:42 PM · camerainputiphoneguitexture

Triggering Main Camera Script with GUITexture

So on my main camera I have a script to zoom in, and on my GUITexture I have a script that makes it a button

Here is my Zoom.js script,

 var zoom : int = 20;
 var normal : int = 60;
 var smooth : float = 5;
 private var isZoomed = false;
 function Update () {
       if (Input.GetButtonDown ("zoombutton")) {
           isZoomed = !isZoomed; 
      }
 
      if(isZoomed == true){
           camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);
      }
      else{
         camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);
      }
 }

and here is my ZoomButton.js script,

     var recoveryTime = 10;
 
 private var delay = 0;
 
 function Update () { if (delay>0){delay -=1;}
 
           if (delay == 0){            if (iPhoneInput.touchCount ==1){
 
 
           var currentTouch:iPhoneTouch = iPhoneInput.touches[0]; 
 
       if(currentTouch.phase ==
 iPhoneTouchPhase.Began && guiTexture.HitTest(currentTouch.position)){ guiTexture.color = Color(0.2, 0.3, 0.4, 0.5);
      }
    }
           }    }

I want to make it so when I press the button it will activate the script on my main camera. I believe the issue is I don't know how to call on the button being pressed to active the zoom function

Appreciate all and any help, Thanks!

Comment
Add comment · Show 1
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 reptilebeats · Jul 25, 2012 at 11:15 PM 0
Share

you could have a go with using enabled = true and false, enable the zoom script when touched and disable when let go.

or you could use a while statement so in your guy script you will call a separate function in the zoom script and that will have a while guy is pressed.

me personnally i wouldn't have two different scripts, as having more than needed update functions can slow down the game especially on the iPhone, i always try to have one update, running at any time, sometimes its unavoidable, but a lot of other stuff can be done through different functions.

1 Reply

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

Answer by Seth-Bergman · Jul 25, 2012 at 11:23 PM

just move the line into the touch statement(also combined to single script):

    var recoveryTime = 10;
     private var delay = 0;
     var zoom : int = 20;
     var normal : int = 60;
     var smooth : float = 5;
     private var isZoomed = false;
 
 function Update () { 
 
 if (Input.GetButtonDown ("zoombutton")) {
           isZoomed = !isZoomed; 
      }
 
      if(isZoomed == true){
           camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);
      }
      else{
         camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);
      }
 
 
 if (delay>0){
 delay -=1;
 }
 
           if (delay == 0){            
 if (iPhoneInput.touchCount ==1){
 
 
      var currentTouch:iPhoneTouch = iPhoneInput.touches[0]; 
 
   if(currentTouch.phase==iPhoneTouchPhase.Began && guiTexture.HitTest(currentTouch.position)){
  guiTexture.color = Color(0.2, 0.3, 0.4, 0.5);
   isZoomed = !isZoomed; 
      }
    }
  }   
 }
Comment
Add comment · Show 1 · 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 Seth-Bergman · Jul 25, 2012 at 11:26 PM 0
Share

note: if you don't want to attach this to your camera , it wouldn't be a problem as long as your camera is tagged as "$$anonymous$$ain Camera".. you just change the lines that say

camera.fieldOfView = etc...

to

Camera.main.fieldOfView = etc...

then it doesn't matter what the script is on

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Missing documentation - iphoneinput class 1 Answer

How do I invert the Y axis in Penelope tutorial? 3 Answers

How to turn on camera light (make a flashlight) on iPhone/iPad? 2 Answers

How to turn on camera light on iPhone? 0 Answers

iPhone input multitouch 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