Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
8
Question by Dev · Apr 02, 2010 at 11:16 AM · cameraswitchrelative

Switching between cameras

Hi, I would like to switch between cameras depending on the position of my player position, how can I do this please?

Thanks a lot for your time.

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

Answer by Jason_DB · Apr 02, 2010 at 01:55 PM

You can activate and deactivate cameras if you can get a hold of the object that holds them.

//cameraObject is the gameObject which holds the camera

cameraObject.camera.active = false;

So If you had a script which kept track of all the cameras in your scene then you could switch cameras easily. For example here is a function which would go through an array of camera objects and turn a certain one on (based on the index sent to it).

var cameras : GameObject[];

function SelectCamera (index : int) { for (var i : int=0 ;i<wcameras.length; i++) { // Activate the selected camera if (i == index){ cameras[i].camera.active = true; // Deactivate all other cameras }else{ cameras[i].camera.active = false; }

}

You could use this function by calling it with a message

BroadcastMessage ("SelectCamera", 1);

or by outright calling it

SelectCamera(1);

You just need to get hold of the instance of the script it's in

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
6

Answer by straydogstrut · Apr 02, 2010 at 02:02 PM

DastardlyBanana's answer would be more flexible, but i'll post my (very simple!) answer here anyway:

You could check for a collision with a collider and then enabled/disable your cameras, so:

var Camera1 : Camera; var Camera2 : Camera;

function Start(){ Camera1.enabled = true; Camera2.enabled = false;

}

function OnTriggerEnter (other : Collider) {

 if(other.gameObject.name == "switch_camera"){

     Camera1.enabled = false;
     Camera2.enabled = true;

 }

}

function OnTriggerExit (other : Collider) {

 if(other.gameObject.name == "switch_camera"){

     Camera1.enabled = true;
     Camera2.enabled = false;

 }

}

Camera1 and Camera2 are assigned in the editor, or you could assign them with code.

Cheers.

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 askerer · Apr 22, 2010 at 09:19 AM

Thanks because I've just looked at your answer I had a lot o thngs to do but it's not as interresting as your answer thanks to you 2!!

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 spinaljack · Apr 22, 2010 at 02:36 PM 0
Share

$$anonymous$$eep comments off of the answers area

avatar image
0

Answer by ImRipken · Oct 07, 2016 at 10:03 PM

This script worked for me. It only works for 2 camera's as far as I know but you might be able to edit it.

var cam1 : Camera; var cam2 : Camera;

function Start() { cam1.enabled = true; cam2.enabled = false; }

function Update() {

 if (Input.GetKeyDown(KeyCode.C)) {
     cam1.enabled = !cam1.enabled;
     cam2.enabled = !cam2.enabled;
 }

}

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

1 Person is following this question.

avatar image

Related Questions

how to have an object positioned relative to the screen(like a button) 1 Answer

Rotate object relative to camera's view 2 Answers

Camera switch after specific time 1 Answer

Camera follows target rotation 3 Answers

Camera switching by trigger 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