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 Aug 28, 2013 at 02:41 PM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Aug 27, 2013 at 05:16 AM · c#camerakeycodecarsdoors

Camera enable/disable problem.

I have this car with some cameras and they need to be disabled when I exit it and enabled when I enter it and change camera view. However I need to use only 2 buttons in order to do it. One for getting in and out and 1 for changing.

Ok so all that pretty much works except that after I exit the car all cameras get disabled on exiting with the same button that I enter the car with. So when I want to renter the car it disables the cameras.

I would I stop it from disabling going in whilst making disable going out?

Code:

 //This is on exiting.
 
 public Camera camera01;
 
 if(Input.GetKeyDown(KeyCode.E)){
 
    camera01.enabled = false;
 
 
 
 
 }

 //This is on entering in the player script, the exiting is on the cars script.
 
 // the CarComp is the script that gets enabled and along with the cameras attached to it. This is the script from above.
 
 if(Input.GetKeyUp(KeyCode.E)){
 
    vehicle.Getcomponent<CarComp>().enabled = true;
 
 
 
 }


So again my problem is that I need the the E button to not disable cameras on getting into the car but do disable them while getting out.

Comment
Add comment · Show 12
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 getyour411 · Aug 27, 2013 at 05:26 AM 0
Share

Could you do something like if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E)) && !isInCar) then disable

avatar image DeadKenny · Aug 27, 2013 at 03:10 PM 0
Share

Is there an even more simple way? Just out of curiosity?

Busy testing your answer now.

avatar image DeadKenny · Aug 27, 2013 at 06:10 PM 0
Share

Well I can't get it to work.

Confused as hell now. Can't think.

$$anonymous$$aybe I should make two buttons? Not good game making practice though, dam it.

avatar image animalphase · Aug 27, 2013 at 07:26 PM 1
Share

It would help if you posted a little more code exactly what is happening.

However, you probably shouldn't tie this camera toggle directly to a keypress. It would be better to have an "EnterCar" function and an "ExitCar" function. Within these functions, enable or disable the proper cameras.

avatar image TrickyHandz · Aug 27, 2013 at 07:45 PM 1
Share

What functions are you enabling and disabling your camera in? Are you using OnEnable() and OnDisable() respectively? As was mentioned by charlestheoaf, more code would help to deter$$anonymous$$e what is causing the problem.

Show more comments

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Sajidfarooq · Aug 27, 2013 at 08:06 PM

Well duh! Unless you have forgotten to post any other code, your activation is happening in Start which is only called once in the life-time of an object. So once you deactivate, you never activate again.

As @TrickyHandz suggested, use OnEnable() instead of "Start". You may also need to create some flags to maintain state.

Comment
Add comment · Show 2 · 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 DeadKenny · Aug 27, 2013 at 08:16 PM 0
Share

LOL ok I am a retard.

See I have never come across that OnEnable and OnDisable thing yet.

Ok ok ok THAN$$anonymous$$ you very much everyone.

avatar image Sajidfarooq · Aug 28, 2013 at 08:43 AM 0
Share

Remember to mark the answer you prefer as "answered" so others that have the same question know the correct answer.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Release camera 1 Answer

How to rotate camera around object smoothly in fixed intervals 1 Answer

PS3 third person camera orbit script C# 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