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
1
Question by malcolmtwl · Jan 17, 2012 at 01:15 AM · cameracontrollerswitch

Singling out mutiple Character movement

Hi, my game consists of two characters which means i have two character controllers (default). Whenever i switch cameras and move both characters move together, when i only need to move the character i am focusing on.

To switch between characters i use this code (Characters have 2 cameras each) :

Character1 > Camera 1 and 2
Character2 > Camera 3 and 4

var camera1 : Camera; var camera2 : Camera; var camera3 : Camera; var camera4 : Camera;

public var startCamera : int = 1;

function Start () { camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false; startCamera = 1; }

function Update () { if (Input.GetKeyDown ("c") && (startCamera == 1)) { startCamera = 3; camera1.enabled = false; camera2.enabled = false; camera3.enabled = true; camera4.enabled = true; }

else if (Input.GetKeyDown ("c") && (startCamera == 3)) { startCamera = 1; camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false; } }

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by senad · Jan 17, 2012 at 08:38 AM

I am guessing that your character controllers are listening on user inputs and do not know if the character is actually active or not. In that case you can add a simple if-statement which checks if the character is currently active and should be moved / controlled or not.

For example you could check on the startCamera variable or define a flag in the controller script, which you turn on or off when you switch characters.

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 malcolmtwl · Jan 19, 2012 at 12:16 PM 0
Share

erm ohk ty will try

avatar image
0

Answer by malcolmtwl · Jan 19, 2012 at 01:30 PM

This is the new code, i renamed the charactercontrollers differently and used this in my camera switcher code

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 malcolmtwl · Jan 19, 2012 at 01:30 PM

var camera1 : Camera; var camera2 : Camera; var camera3 : Camera; var camera4 : Camera;

var Tumble : MonoScript; var Blueboy : MonoScript;

public var startCamera : int = 1;

function Start () { camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false; startCamera = 1; Tumble.enabled = true; Blueboy.enabled = false; }

function Update () { if (Input.GetKeyDown ("c") && (startCamera == 1)) { startCamera = 3; camera1.enabled = false; camera2.enabled = false; camera3.enabled = true; camera4.enabled = true;

Tumble.enabled = false; Blueboy.enabled = true; }

else if (Input.GetKeyDown ("c") && (startCamera == 3)) { startCamera = 1; camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false;

Tumble.enabled = true; Blueboy.enabled = false; } }

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

setting a character controller orientation by script 1 Answer

Swapping Cameras Disables Keyboard Input 3 Answers

UI Buttons switch cameras 3 Answers

Main Camera Switch? 3 Answers

Mobile Character controller Moving in world space 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