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 DemocracyDealer · Jul 16, 2020 at 06:52 PM · cameracamera script

My C# Script Won't Switch Camera

Hey, I'm extremely new to unity, c#, and just coding in general. I'm making a little game and want to make my camera switch when my player object is destroyed (my main camera is attached to my player and is also destroyed, so that's why). Since I'm new, I try to code by myself and follow tutorials instead of just copy code. I understand that means I'll make a lot of errors. Here is one I just can't find my way around.

public class NewBehaviourScript : MonoBehaviour { // Update is called once per frame void Update() { MakeMain(GameObject.Find("Camera1")); } void MakeMain(GameObject secondary) { if(Camera.main == null) { secondary.gameObject.SetActive(true); } } }

When my player object is destroyed the Camera.main will come back null. I have my Camera1 cam set unactive. I'm not sure why it isn't being set to active after my main camera is destroyed and being displayed on the screen. It just says, "Display 1 No cameras rendering". I have the script set to Camera1 currently, which I think that's how it should be. This might be a little confusing (I'm confused), but a little help would be awesomely appreciated. Again, you might think I'm dumb, but I'm just really new to this. If you need any more clarification on my question, I'll reply ASAP. Thanks so much!

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

Answer by DemocracyDealer · Jul 16, 2020 at 11:56 PM

That was not the fix. In fact, it is far more simple. I ended up changing the camera true/false instead. Here is the final script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class thing : MonoBehaviour
 {
 
     private Camera myCamera;
 
 
     // Start is called before the first frame update
     void Start()
     {
 
         myCamera = GetComponent<Camera>();
 
         myCamera.enabled = false;
     }
 
     void Update()
     {
         MakeMain();
     }
     void MakeMain()
     {
 
         myCamera = GetComponent<Camera>();
 
         if (Camera.main == null)
         {
             myCamera.enabled = true;
         }
     }
 }
 
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
-1

Answer by jemules · Jul 16, 2020 at 07:51 PM

Here the fix https://pastebin.com/xx0w83jH

Comment
Add comment · Show 4 · 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 DemocracyDealer · Jul 16, 2020 at 08:11 PM 0
Share

I'm not sure why, but that didn't work. I added the cameras in the inspector, and yet it still says, "Display 1 No cameras rendering". This is a big hassle, and I'm not sure why that didn't work. ugh

avatar image DemocracyDealer · Jul 16, 2020 at 08:11 PM 0
Share

What am i missing here?

avatar image DemocracyDealer · Jul 16, 2020 at 08:13 PM 0
Share

I know I can just change the priority and have to active at once, but that makes the screen look all grainy.

avatar image DemocracyDealer · Jul 16, 2020 at 08:13 PM 0
Share

I just am absolutely stumped.

avatar image
0

Answer by crawman06 · Aug 06, 2021 at 11:47 AM

I think I have the answer, (I assume you already did it seeing as this was a long time ago) I think I had the same problem as you, what I did was, in the Camera Component there is an option to change the "Target Display". So by changing both/all the camera in the seen to the same Display (this will make them acts like there overlapped) by activating and/or deactivating a camera it should show the other one(s). (I hope that helped, I don't really know much about Unity, or coding for that mater)

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

199 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 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 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 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 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 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 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 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 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 avatar image

Related Questions

On looking to far up or down Random Rotation bug 1 Answer

Switching to the player camera 1 Answer

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

Camera.ViewportToWorldPoint giving different values 0 Answers

Making a camera switch in JS, how do I add more cameras? 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