• 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 machinew · Feb 18, 2011 at 06:37 PM · charactercharactercontroller

second character controller ???

Hello everybody,

i want a make switchable character controllers and i try something like this

var Character1 : GameObject;

var Character2 : GameObject;

function Update () {

if(Input.GetKeyDown ("1")) Character1.GetComponent(CharacterMotor).enabled = true; Character2.GetComponent(CharacterMotor).enabled = false;

if(Input.GetKeyDown ("2")) Character1.GetComponent(CharacterMotor).enabled = false; Character2.GetComponent(CharacterMotor).enabled = true; }

when i pressedd key 1 two controller move together

but when i pressed key 2 its work perfectly

how can i fix that (thats my firspost sory about everything)

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Mike 3 · Feb 18, 2011 at 07:02 PM

You're missing braces to specify which parts are in the if:

if(Input.GetKeyDown ("1"))
{
    Character1.GetComponent(CharacterMotor).enabled = true;
    Character2.GetComponent(CharacterMotor).enabled = false;
}
if(Input.GetKeyDown ("2"))
{
    Character1.GetComponent(CharacterMotor).enabled = false;
    Character2.GetComponent(CharacterMotor).enabled = true;
}
Comment
Add comment · Show 1 · 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 machinew · Feb 18, 2011 at 07:39 PM 0
Share

thank you so much $$anonymous$$ike

avatar image
0

Answer by machinew · Feb 18, 2011 at 07:49 PM

i have a another little problem when i played the game characters move together i want a make only Character1 is enable i tried

var Character1 : GameObject;
var Character2 : GameObject;
var Chaarcter1Enabled = true;
var Chaarcter2Enabled = false;

how can i fix it ? Thank you again

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
0

Answer by Unamine · Feb 18, 2011 at 10:35 PM

Try this:

var Character1 : GameObject; var Character2 : GameObject; var isActive1 = false; var isActive2 = false;

function Update () {

if(Input.GetKeyDown ("1") && isActive2 == true || isActive2 == false) { Character1(); }

if(Input.GetKeyDown ("2") && isActive1 == true || isActive1 == false) { Character2(); }

function Character1() { Character1.GetComponent(CharacterMotor).enabled = true; Character2.GetComponent(CharacterMotor).enabled = false; }

function Character2() { Character1.GetComponent(CharacterMotor).enabled = false; Character2.GetComponent(CharacterMotor).enabled = true; }

any questions post here again.

Hope that helps

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
0

Answer by machinew · Feb 19, 2011 at 11:01 AM

i just uncheck Character 2 Character Motorin the inspector panel and its work

Thank You Guys

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How do I move arms and legs in .fbx format? 1 Answer

Let Character Controller jump. 1 Answer

add camera collision without CharacterController 1 Answer

Camera Orbit Character Rotation 1 Answer

so my character will not move forward just spins left and right 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