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 wesley · Apr 06, 2011 at 09:19 PM · cameraswitch

camera switch not working

hey guys this script i got does not work i want to switch view from camera 1 to camera 2 afrter 10 sec but i cant get it to work can you hepl me please

var waitTime = 10; var numberOfCameras = 7;

function Start() {
for (var i = 0; i<=numberOfCameras;i++) { var oldCamera = GameObject.Find("Camera"+(i-1)); var newCamera = GameObject.Find("Camera"+i);

     oldCamera.active = false;
     newCamera.active = true;

     yield WaitForSeconds(waitTime);
 }

}

Comment
Add comment · Show 1
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 wesley · Apr 06, 2011 at 09:20 PM 0
Share

oooops sorry that the sript isnt corrrent uploaded

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by DaveA · Apr 06, 2011 at 09:28 PM

Do you have a camera called Camera-1 ? Or do they start with Camera0? Because this script wants to start with Camera-1 and go to Camera7

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 Bampf · Apr 06, 2011 at 10:16 PM 1
Share

Double-check your console, make sure there aren't any errors being displayed when your game is running. And for safety's sake, you should add checks for null to avoid referencing oldCamera or newCamera if one is not found. (In general, whenever you call Find you should check that you got something back before dereferencing it.)

avatar image
1

Answer by Statement · Apr 06, 2011 at 10:26 PM

It's because you're disabling the game object, so you can't find it the next search. You also seemed to have a very odd for loop. I changed so it looks for

  • Camera0
  • Camera1
  • Camera2
  • Camera3
  • Camera4
  • Camera5
  • Camera6

Try storing them in a list instead:

import System.Collections.Generic;

var waitTime = 10; var numberOfCameras = 7;

function Start() {

 // 1. Find all cameras. 
 // You probably want to disable them all as well, 
 // so no other camera is active.
 var cameras = new List.&lt;GameObject&gt;(numberOfCameras);
 for (var i = 0; i &lt; numberOfCameras; ++i) {
     cameras.Add(GameObject.Find("Camera"+i));
     cameras[i].active = false;
 }

 // 2. Loop through them and toggle active.
 var oldCamera : GameObject;
 for (var newCamera in cameras) {
     if (oldCamera) oldCamera.active = false;
     if (newCamera) newCamera.active = true;
     yield WaitForSeconds(waitTime);
     oldCamera = newCamera;
 }

}

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 DaveA · Apr 06, 2011 at 11:24 PM 0
Share

Could he just enable/disable the Camera component, leaving the object active?

avatar image DaveA · Apr 06, 2011 at 11:26 PM 0
Share

Assu$$anonymous$$g he started with all active cameras, it shouldn't have mattered about deactivating them, he's 'done' with the deactivated one(s). But a list is good. $$anonymous$$y own solution was to have an array of transforms whereby I drag (inactive) cameras, but I don't want to give away too much ;)

avatar image
0

Answer by adam_unity566 · Jun 21, 2020 at 07:46 PM

Well, the simple answer to your problem is that your SetActive statement should be oldCamera.SetActive(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

1 Person is following this question.

avatar image

Related Questions

Character movement when I switch cameras. 0 Answers

Switch to second camera which has all the GUI 3 Answers

Switching cameras (JavaScript) 0 Answers

How to make camera position relative to a specific target. 1 Answer

Multiple Camera.main.ScreenPointToRay 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