Simple Problem Help Needed!!!

I have several cameras and just want a disabling event (which works) to occur when its on a certain camera but not the others as my current script makes the event occur on all cameras. This seems like a simple task but I can’t figure out how to make an "if (camera) and only that (camera), then (event) to work as it’s a gameobject and I’m not sure how to get an if statement to work with a gameobject camera. I have been dealing with this for 4 days and really need help. I’m starting to feel like giving up but I’m not that kind of person and I’m really happy with my game so far.

I don’t know what you mean by “disabling event,” but generally in Unity you give the reference to the camera (or cameras) that you want to a script with a public variable, then do what you need to that one (or more) cameras.

If I have “public Camera cam” and want to reference that in a bool if statement, if camera is active do { whatever }, how would I do that?

Cameras can be enabled or not. GameObjects can be active or not.

I’m still not 100% sure I understand your question.

But given this:

(and properly filled out in the editor!), the code would be:

if (cam.enabled)
{
  // do something
}

This works when disabling the button permanently. I need to make it think “cam” is not enabled when it moves to another camera.

I think I lost you at “button…” I thought we were talking about cameras.

You might want to just go work through some basic UI and/or camera control tutorials.

It’s super-simple stuff to grasp but you have to be extremely clear what you’re trying to do first.

Sorry, I should have reread my response. The

  • if (cam.enabled)
  • {
  • // do something
  • }

function works but is on permanently and not just when “cam” is the active camera. I’ve watched a dozen tutorials and haven’t found anyone touching on it which is odd, it seems like it would be a common thing?

Let’s go back to the beginning. What is your goal? Why do you have multiple cameras at the first place? It is very uncommon having more than one camera, except for VERY specific purposes (like in the built-in render pipeline and you’re making an FPS and you need to render your weapons on the top of the main camera), and so on.
So, please describe what you want to do (I mean what’s your goal and forget the camera and how they work).

Basically I have an object that has several cameras around it, each with a canvas, that is modified by the user via buttons. I do have several cameras and canvases in one scene which I realize can be frowned upon yet I’m unsure how I would advance a customized object into a new scene and back to an old one. The multiple canvases are interfering with each other so I am trying to figure out how to get them to only work on the intended camera, which may or may not be frowned upon?

So you’re rendering several camera for the user at once?

Now that you mention it: yes, maybe I should make the cameras and their canvases disabled when not in use. How would I achieve this though?

Every gameobject has setActive method.

BTW, side note: you can pick up Cinemachine as well, it allows you to setup multiple virtual cameras and have only one active real camera which can be moved on easy ways between the vantage points of these virtual cameras.

This is what has been causing my trouble for days: setActive won’t work on IF statements, only “Enable” ones will work on bool statements from what I’ve encountered so how can I make “setActive” interact with an IF statement? :if a camera is active (not the enabled function), then (event)

If statement how? Give me a proper code example what are you doing. SetActive is setting(!) the value. If you want to check if a game object is active in the scene or not, use the activeInHierarchy property.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ded2 : MonoBehaviour
{

public Button button0000;
public Button button1;
public Button button2;
public Button button3;
public Button button4;
public Button button5;
public Button button6;
public Button button7;
public Button button8;
public bool discan2;

void Start()
{
button0000.onClick.AddListener(Disable);
if (discan2 == true)
{

button1.interactable = false;
button2.interactable = false;
button3.interactable = false;
button4.interactable = false;
button5.interactable = false;
button6.interactable = false;
button7.interactable = false;
button8.interactable = false;
}
}

void Disable()
{
if (discan2 == false)
{

button1.interactable = true;
button2.interactable = true;
button3.interactable = true;
button4.interactable = true;
button5.interactable = true;
button6.interactable = true;
button7.interactable = true;
button8.interactable = true;
}
}

}

This is the closest I have gotten tonight, didn’t work.

hmm, I may have got it to work by changing the second discan2 to true but it’s still messy

Nope, it works forwards but going backwards messes it up.