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
-1
Question by user-3180 (yahoo) · Jun 24, 2010 at 01:04 AM · animationdelaytogglezoom

Sniper zooming (toggle)

how do i make it so when i click "z" once, and don't hold it, the camera will change.

private var baseFOV : float;

function Start () { baseFOV = Camera.main.fieldOfView; }

function Update () { if (Input.GetKey("z")) Camera.main.fieldOfView = 10; else Camera.main.fieldOfView = baseFOV;

}

Thats my script and if i hold z it will zoom in but how do i make it toggle on/off. and then how do i make all that so when i Zoom In there is a .5 sec delay.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Murcho · Jun 24, 2010 at 03:45 AM

Just store a bool in your script to toggle it like so

private var baseFOV : float; private var zoomToggle : bool;

function Start () { baseFOV = Camera.main.fieldOfView; zoomToggle = false; }

function Update () { if (Input.GetKey("z")) { if(zoomToggle) { zoomToggle = !zoomToggle; Camera.main.fieldOfView = 10; } else { zoomToggle = !zoomToggle; Camera.main.fieldOfView = baseFOV; } } }

You will have to be a bit more specific about you 0.5 second delay. Do you want the delay to be while zooming in, do you want it to be a delay between pressing the button then applying the new zoom FOV?

EDIT : Fixed the toggle, wasn't actually toggling.

To add the pause, you can yield, but you can't do that inside an Update loop, so will have to add another function to handle it.

function Zoom(float zoomValue) {
    yield WaitForSeconds(0.5);
    Camera.main.fieldOfView = zoomValue;
}

Replace the calls in the update loop that set the fov value with a call to the Zoom function and it should work.

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 3dDude · Jun 24, 2010 at 03:14 PM 0
Share

you could try using input.Get$$anonymous$$eyDown.

avatar image user-3180 (yahoo) · Jun 24, 2010 at 03:47 PM 0
Share

... i don't understand the delay? how do i put it in?(I'm the worst scripter ever i only started trying to make my own scripts like a week ago... and i never followed any scripting tutorials?)

avatar image user-3180 (yahoo) · Jun 24, 2010 at 03:58 PM 0
Share

Sorry for so many questions and stuff but also it toggles in perfect but it is difficult to toggle it out you have to hold it like for 2 frames and then let go our something.

avatar image
1

Answer by mirw9 · Jun 24, 2011 at 02:45 PM

use this

var camera1 : Camera;

var camera2 : Camera;

function Start () {

camera1.enabled = true;

camera2.enabled = false;

}

function Update () {

if (Input.GetKeyDown ("z")){

   camera1.enabled = false; 
 
   camera2.enabled = true; 
 

}

if (Input.GetKeyDown ("z")){

   camera1.enabled = true; 
 
   camera2.enabled = false;

 

}

}

i use a modified version

EDIT: to make it so you have to press the button again to go back to normal view use this:

var camera1 : Camera;

var camera2 : Camera;

function Start () {

camera1.enabled = true;

camera2.enabled = false;

}

function Update () {

if (Input.GetKeyDown ("z")){

camera1.enabled = false;

camera2.enabled = true; }

if (Input.GetKeyUp ("z")){

camera1.enabled = true;

camera2.enabled = false; }

}

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

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

1 Person is following this question.

avatar image

Related Questions

Toggle zoom 1 Answer

animations back and forth Again 0 Answers

Can I make animations snap to a frame? 1 Answer

Make ball flip around cube... 0 Answers

animation script help 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