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 NerdGameStudio · Jun 09, 2014 at 12:24 PM · camerajavascriptswitching

Switching Camera not working

Hi everybody,

I'm having a difficult time coding a switch on two camera's. For some reason I can't get the switch to work properly, perhaps someone can help me out?

Situation: I set up a first person controller and a car controller. They work fine when controlling seperatly. I made a trigger in order for the switching camera (and controllers) to work ingame. When I test this and look at what's going on in Unity's scene view, everything works fine, except the camera is not switching.

I tried two things: When I state that the camera is .active the switch ingame works for one time. When I switch back, all I see is a white screen (while the controller and everything still works). When I state that the camera is .enabled it's not working at all.

I left out some parts that are not involving the camera changing, so here's the (adjusted) script:

 var PlayerCamera : Camera;
 var CarCamera : Camera;
 var isPlayerVisable : boolean = false;
 var TextShow : boolean; 


function Start ()

 {
     PlayerCamera.camera.enabled = true;
     CarCamera.camera.enabled = false;
 }     

 function Update ()
 {
 if (Input.GetKeyDown(KeyCode.E) && isPlayerVisable == true)
 {

PlayerCamera.camera.enabled = false;

 CarCamera.camera.enabled = true;
 
 TextShow = false;
 isPlayerVisable = false;

}

else {

 if (Input.GetKeyDown(KeyCode.E) && isPlayerVisable == false)
 {

CarCamera.camera.enabled = false;

PlayerCamera.camera.enabled = true;

 TextShow = true;
 isPlayerVisable = true;
 
 }
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 DrunkFish01 · Jun 09, 2014 at 12:36 PM

do

 var PlayerCamera : GameObject;
 var CarCamera : GameObject;

just set the objects on off like

 PlayerCamera.SetActive(false);
 CarCamera.SetActive(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 NerdGameStudio · Jun 16, 2014 at 07:15 PM 0
Share

Thanks for your comment ChrisHellas! Unfortunately the code you provided doesn't resolve my problem. The same issue remains.

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

Switching Between Cameras JavaScript 0 Answers

Switching cameras (JavaScript) 0 Answers

Destroy object question! 3 Answers

Camera switching with iTween Touch 1 Answer

Set Max Rotation On Weapon Sway 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