- Home /
How to change characters with pressing a button
Hi, I am making a GTA clone. I want to press E to change from character to car. I know how to change cameras.
Answer by yigo2413 · Jan 29, 2012 at 03:53 AM
1- Add a trigger to car. Basically add a cube to the car and parent it, select isTrigger and close MeshRenderer. Let's tag it as "carTrigger" .
Now add Player this code :
var item1 : GameObject ; //select the car
function OnTriggerStay(c : Collider)
{
if(c.gameObject.tag == "carTrigger")
{
if(Input.GetKeyDown("e"))
{
gameObject.active = false ;//player is not active
item1.active = true ;//car is active
}
}
}
this is a way you can use, but there are many ways without using active . While car is not active you can use a dublicade car without driving code and deactivate it when your car with driving script becoming active.
3 errors;
Assets/Standard Assets/Terrain Grass/Sandbox Controller.js(13,3): BCE0043: Unexpected token: if.
Assets/Standard Assets/Terrain Grass/Sandbox Controller.js(13,53): BCE0043: Unexpected token: ).
Assets/Standard Assets/Terrain Grass/Sandbox Controller.js(13,67): BCE0044: expecting :, found '='.
this is the script called sand box controller:
var CameraPlayer1 : Camera; var CameraPlayer2 : Camera; var Player1 : GameObject; var Player2 : GameObject;
function OnTriggerEnter (col : Collider) {
if (isDriving == false) { isDriving = true; GetIn(); } }
function GetIn() { { if(Input.Get$$anonymous$$eyDown("E")) && ((isDriving) == true)) { isDriving = false; GetOut(); } } { Player1.active = true; Player2.active = false;
CameraPlayer1.active = true;
CameraPlayer2.active = false;
Player1Script.GetComponent("PlayerCar_Script").enabled = true;
Player2Script.GetComponent("FPSWalker").enabled = false;
} }
function GetOut() {
{ if(Input.Get$$anonymous$$eyDown("E")) { Player1.active = false; Player2.active = true;
CameraPlayer1.active = false;
CameraPlayer2.active = true;
Player1Script.GetComponent("PlayerCar_Script").enabled = false;
Player2Script.GetComponent("FPSWalker").enabled = true;
} }
there are many things unclear I think. You should try to do some basic tutorials and understand them, before you go ahead I think.
The function OnTriggerEnter gets only called at the very moment you enter the collider. If you not press E at this very moment, you would have only a chance to enter the car again, if you left the collider and entered it again, while pressing $$anonymous$$ Sure thats not what you want.
Also to call the function GetOut while beeing in the function GetIn is hilarious.
None the less I wish you good luck with your GTA Clone ;)
this is the script line
if(Input.Get$$anonymous$$eyDown("E")) && ((isDriving)) == true)) { isDriving = false; GetOut(); } }
i am getting these errors:
BCE0044: expecting :, found '='.
BCE0043: Unexpected token: ).
BCE0043: Unexpected token: if.
this is the script line
if(Input.Get$$anonymous$$eyDown("E")) && ((isDriving)) == true)) { isDriving = false; GetOut(); } }
i am getting these errors:
BCE0044: expecting :, found '='.
BCE0043: Unexpected token: ).
BCE0043: Unexpected token: if.
Answer by justin8567a · Oct 25, 2013 at 01:23 AM
You might want check this out: http://forum.unity3d.com/threads/207001-GTA-V-Character-Switching-System-Character-Wheel-(COMING-SOON)
Your answer
Follow this Question
Related Questions
could someone help with entering/exiting a vehicle? 0 Answers
How do I make a combination of orbit and TPS camera like in gta 0 Answers
Making a game like gta 2 Answers
Grand Theft Auto Style Controller 0 Answers
Horse Animset Pro and Invector Melee AI 0 Answers