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 Looi · Jun 04, 2014 at 02:24 AM · cameracharacterswitch

How can I change the character beign controled and the camera with a button?

Hey folks, this is the first game I'm programming alone and here's the situation: I have 3 characters that need to be controled. It's an Isometric camera and you must switch the characers with buttons(not specific). There's already a camera following them but I can't figure how to change the camera without controlling all the characters at once.

In short, I'm looking for a way to control 3 characters separatedely, each one of the with a different camera.

OBS: C# codes wil help me more since I'm trying to learn it.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by minefriek · Jun 04, 2014 at 03:11 AM

Well Im no expert in C#, though I've used it for a couple things, but I can show you what I did in javascript for an FPS/RTS game. the principals are basically the same

 var cam1: Camera;
 var cam2: Camera;
 var cam3: Camera;
 
 function Start() {
     cam1.enabled = true;
     cam2.enabled = false;
     cam3.enabled = false;
     Screen.lockCursor = true;
 }
 
 function Update() {
 
     // First Person/Third Person Toggle
     if (Input.GetKeyDown(KeyCode.PageUp) && (cam1.enabled == true)) {
         cam1.enabled = false;
         cam2.enabled = true;
         cam3.enabled = false;
         Screen.lockCursor = true;
     }
     else if (Input.GetKeyDown(KeyCode.PageUp) && (cam2.enabled == true)) {
         cam1.enabled = true;
         cam2.enabled = false;
         cam3.enabled = false;
         Screen.lockCursor = true;
     }
     
     // Strategy Toggle
     if (Input.GetKeyDown(KeyCode.PageDown) && (cam1.enabled == true)) {
         cam1.enabled = false;
         cam2.enabled = false;
         cam3.enabled = true;
         GameObject.Find("Avatar").GetComponent(CharacterController).enabled = false;
         Screen.lockCursor = false;
     }
     else if (Input.GetKeyDown(KeyCode.PageDown) && (cam2.enabled == true)) {
         cam1.enabled = false;
            cam2.enabled = false;
         cam3.enabled = true;
         GameObject.Find("Avatar").GetComponent(CharacterController).enabled = false;
         Screen.lockCursor = false;
     }
     else if (Input.GetKeyDown(KeyCode.PageDown) && (cam3.enabled == true)) {
         cam1.enabled = true;
         cam2.enabled = false;
         cam3.enabled = false;
         GameObject.Find("Avatar").GetComponent(CharacterController).enabled = true;
         Screen.lockCursor = true;
     }

Do not just drag and drop this into a javascript and port it into your game

basically what your looking for to disable a character controller is the GameObject.Find part that toggles fps to rts in this case. However the code can be pretty much adapted to your needs.

The variables specified at the top of the code allow you to select the cameras you wish to switch between meaning theres less hassle setting everything up.

But the key thing here for you is the gameobject part. What you need to do is to is to enable or disable the character controller for your 3 characters depending on which camera is selected. This allows for you to control one character at a time instead of having the problem of all of them moving at once

I probably just confused you more but let me know if this helps.

Comment
Add comment · Show 2 · 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 Looi · Jun 04, 2014 at 12:03 PM 0
Share

I got the concept for it, Thanks! But this script goes to the cameras or the character?

avatar image Looi · Jun 05, 2014 at 11:47 AM 0
Share

Got it working now. Thanks. This is the code I used, for future references.

 void Start() {
     camera.enabled = true;
     camera2.enabled = false;
     camera3.enabled = false;
         GameObject.Find("Filho").GetComponent<$$anonymous$$ovimentoFilho>().enabled = true;
         GameObject.Find("$$anonymous$$ae").GetComponent<$$anonymous$$ovimentoPais>().enabled = false;
         GameObject.Find("Pai").GetComponent<$$anonymous$$ovimentoPais>().enabled = false;
     }
     
     void Update() {
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Alpha2) && (camera.enabled == true)) {
             camera.enabled = false;
             camera2.enabled = true;
             camera3.enabled = false;
             //Se a camera estiver no filho, vai para a $$anonymous$$ae
 
             GameObject.Find("Filho").GetComponent<$$anonymous$$ovimentoFilho>().enabled = false;
             GameObject.Find("$$anonymous$$ae").GetComponent<$$anonymous$$ovimentoPais>().enabled = true;
             GameObject.Find("Pai").GetComponent<$$anonymous$$ovimentoPais>().enabled = false;
             GameObject.Find("Filho").GetComponent<>() = false;

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

22 People are following this question.

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

Related Questions

character switching on collision 1 Answer

switch character 1 Answer

setting a character controller orientation by script 1 Answer

How to switch between four characters when a button is pressed? 1 Answer

changing player (getting in vehicles) 3 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