Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by maggot · Jul 31, 2010 at 03:48 PM · playercharactercontrolsselect

Player or character select

How do I make it so I can change players for the user to control. For instance so '1' selects tank, '2' selects helicopter? Similar to the character/player select system used in beat-em-ups/shmups.

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
2
Best Answer

Answer by StephanK · Jul 31, 2010 at 07:46 PM

I'd try having a manager object with references to all players/vehicles control scripts. Then if you press a certain button I'd activate one and deactivate all other vehicle's control script.

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
avatar image
2
Best Answer

Answer by spiel2001 · Jul 31, 2010 at 09:30 PM

Try something like this: Create an empty game object called "PlayerInput" and attach the movement control script to it including the following...

// note... each character controller must have a camera defined // that represents the viewpoint for that controller

var defaultController : int = 0; var movementSpeed : double = 5.0;

var controllers : CharacterController[]; var cameras: Camera[];

private var currentCharacter; private var currentController;

function Start() { currentCharacter = defaultController; currentController = controllers[currentCharacter];

 for( i = 0; i < cameras.length; i++ )
 {
     if( i == currentCharacter ) cameras[i].enabled = true;
     else cameras[i].enabled = false;
 }

}

function Update() { // player changing views...

 if( Input.GetKeyDown( 'v' ) )
 {
     cameras[currentCharacter].enabled = false;

     currentCharacter++;

     if( currentCharacter == controllers.length )
         currentCharacter = 0;

     currentController = controllers[currentCharacter];
     cameras[currentCharacter].enabled = true;
 }

 // movement for whichever character the player is currently controlling
 // assumes Y is the up axis

 var moveDirection = Vector3( Input.GetAxis ( "Horizontal" ), 0, Input.GetAxis ( "Vertical" ) );

 currentController.Move( transform.TransformDirection( moveDirection ) * movementSpeed * Time.deltaTime );        

}

// EDIT: corrected a bug in the code example

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

No one has followed this question yet.

Related Questions

Understanding Prefabs + Player Spawn Points 2 Answers

Input Script And Mecanim 0 Answers

Alan Wake style 3rd person character controls, help! 1 Answer

My character jumps infinitely, even when in mid-air 1 Answer

2D Movement Problems 2 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