- Home /
The question is answered, right answer was accepted
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.
Could you do something like if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E)) && !isInCar) then disable
Is there an even more simple way? Just out of curiosity?
Busy testing your answer now.
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.
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.
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.
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.
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.
Remember to mark the answer you prefer as "answered" so others that have the same question know the correct answer.
Follow this Question
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