- Home /
Duplicate Question
How to make an Enterable/Exitable Vehicle
Hi, I'm kinda new to Unity and I was wondering if it's possible to make it that when a First Person Controller collides with an object (vehicle in this case) that it will print on the screen "Press E To Drive Vehicle" then you will change to third person and be able to drive the vehicle then press E again to exit it.
I know it's a lot to ask, but please do your best to answer!
please, please, please, conduct a simple search before you ask this
just click on the vehicle tag in your question, even, and half of those questions are 'please make me an enterable/exitable vehicle'
It's your job as a programmer to solve problems. You shouldn't expect to go online and find a solution for every one of them. Think things through and write some code. Then, if it doesn't work, come here and post the parts that don't work and ask specific questions.
Answer by Vonni · Jan 20, 2013 at 03:33 PM
Make a Cube
Remove Mesh renderer
Scale and move to fit around your car (but bigger)
Check the target box on collider
Make a new Javascript
Add:
function OnTriggerEnter (other : Collider) { if(other.gameObject.equals("Player")){ // Show text! } } function OnTriggerExit (other : Collider) { if(other.gameObject.equals("Player")){ // Hide Text! } } function OnTriggerStay (other : Collider) { if(Input.GetKeyDown(KeyCode.E))){ // Enter vehicle } }
And the rest depends on how your game is and is for you to find out! :)
I have a problem with this, I keep getting a $$anonymous$$issing$$anonymous$$ethodException: UnityEngine.GameObject.equals not found and it always prints "Press E To Drive Car" even before I have collided with it, please help!
Try changing
if (other.gameObject.equals("Player"))
to
if (other.gameObject.name == "Player")
Besides the fact that 'gameObject.equals()' doesn't exist (it's 'gameObject.Equals()' ftw), that function tests whether two objects are the same. And, for future reference, going to Google and typing 'Unity GameObject.Equals' will tell you all about it. Additionally, highlighting code and hitting command/ctrl+' (apostrophe) in $$anonymous$$onoDevelop will take you directly to the docs.
can you give me the full script of character and car?i have no knowledge about java.
Follow this Question
Related Questions
Enter/Exit vehicle 0 Answers
Car Enter/Exit Script Multiple Cars Problem 4 Answers
Problem Enter and Exit with Vehicle 2 Answers
How do you make character enter and exit vehicles. 1 Answer
Enter\Exit Car With Doors. 0 Answers