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 logging_out · Dec 30, 2010 at 07:49 PM · camerathird-person

Using a Key to Activate Camera Mouse Look

So I'm creating this third person game using the Third Person Controller script from Unity's 3D platform tutorial to move my character. I want to add on another feature which allows the player to hold down a specific key (for example the F-key) that will freeze the Third Person Controller (not allowing the player to move) and activate my mouse look script. What script would I need to do this?

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
Best Answer Wiki

Answer by MC HALO · Dec 30, 2010 at 07:59 PM

function Update (){

if (Input.GetKey (KeyCode.F)){

GetComponent(" Put the script name over here ").enabled = false;

}

}

hope it helps :) this will disable the script when the F key is pressed. the script above only disables the script. The script Below will allow you to on and off the script with the same key:

var OnScript : boolean = true;

function Update() {

if(Input.GetKey(KeyCode.F) && OnScript ){

GetComponent(AnimationScript).enabled = false; OnScript = false;

} else if (Input.GetKey(KeyCode.F) && OnScript == false ){

GetComponent(AnimationScript).enabled = true;

OnScript = true;

} }

it may look confusing but it is easy to under stand on the new script on top of the update function i have created a check box using a boolean. The check box will be set as true when you run the game and the player script will be enabled. if you press the F key once it will disable the script. You may notice underneath the line

                 **"  if(Input.GetKey(KeyCode.I) && OnScript ){"**

it says OnScript = false this is disabling the check box if it is off the script goes off. and if you press the F key again it will make the check box true again and the script will come back on. I hope this helps :)

if you have any questions regarding this script please ask :)

Try this :

var OnScript : boolean = true;

function Update() {

  if(Input.GetKeyUp(KeyCode.K) && OnScript) {

    OnScript = false; 

     GetComponent(AnimationScript).enabled = false;
   }

   else if (Input.GetKeyUp(KeyCode.K) && !OnScript) {

    OnScript = true;

    GetComponent(AnimationScript).enabled = true;
   }

}

the problem was using Input.GetKey()returns true while the user is holding the key. if you use Input.GetKeyUp() this would return true only when the user releases the key

Comment
Add comment · Show 8 · 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 logging_out · Dec 31, 2010 at 03:13 AM 0
Share

So that works. Now I need to figure out how to reactivate it when the F-$$anonymous$$ey is pressed again.

avatar image MC HALO · Dec 31, 2010 at 03:46 AM 0
Share

what you want to shut it off ? if so you will need to do the following :

avatar image MC HALO · Dec 31, 2010 at 04:34 AM 0
Share

hea :) i have edited the answer above have look

avatar image logging_out · Jan 02, 2011 at 07:42 PM 0
Share

Oh my mistake. I wanted to activate it then shut it off. I'm having a little problem though. It works to shut it off and on, although sometimes I have to hold it down to switch it. Is that just how the script works or is there something that isn't working right?

avatar image MC HALO · Jan 04, 2011 at 03:26 AM 0
Share

no you should be able to tap it. but you have to wait 2 sec before you can hit it again if this is a problem let me know and i will come up with a idea again :)

Show more comments

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

No one has followed this question yet.

Related Questions

how to create a TPS camera view? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Gun clipping through walls in third person shooter 1 Answer

How to get an object's direction relative to the camera? 3 Answers

Using the "ThirdPersonController" Script without its 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