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
0
Question by mashood · Jan 29, 2012 at 02:39 AM · gta

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.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 4 · 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 mashood · Jan 29, 2012 at 05:35 PM 0
Share

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;

} }

avatar image swisscoder · Jan 29, 2012 at 07:14 PM 0
Share

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 ;)

avatar image mashood · Feb 06, 2012 at 01:23 AM 0
Share

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.

avatar image mashood · Feb 06, 2012 at 01:23 AM 0
Share

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.

avatar image
0

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)

Comment
Add comment · 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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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