• 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Customizing 0 Answers

Grand theft auto - Map Waypoint 1 Answer

Camera position/rotation reset after 5 seconds of mouse inactivity 0 Answers

how to change object 0 Answers

About Camera Change & switch GamePlay 1 Answer


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