Hello, I’m new to the land of Unity and I’m trying to muddle my way through. I’m probably having issues due to inexperience using Unity and C#.
In very simple scene, I’m trying to make 2 camera’s switch when a key is pressed on the board (C). Is there a simple method to achieve this using enabled = true?
Other notes that could be of use:
I have followed other vid tuts without success.
I have nested 2 camera’s in a a Empty Game Object… do I need to do this?
I’m a newb.
Morning… Managed to stop it spitting back errors but the camera transitions doesn’t work. Another thing to note is that the object in my scene is flash/blinking rapidly. Any clues?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSwitch : MonoBehaviour {
public Camera camera1;
public Camera camera2;
private void Awake ()
{
camera2.enabled = false;
}
public void SwitchCam ()
{
camera1.enabled = !camera1.enabled;
camera2.enabled = !camera2.enabled;
}
void Update() {
if (Input.GetKeyDown(KeyCode.C))
print("C key was pressed");
SwitchCam ();
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Manycameras : MonoBehaviour {
public Camera camera1;
public Camera camera2;
public Keycode key;
private void Awake ()
{
camera2.enabled = false;
}
public void SwitchCam ()
{
camera1.enabled = !camera1.enabled;
camera2.enabled = !camera2.enabled;
}
}
void Update()
{
if (Input.GetKeyDown (KeyCode.C))
{
Debug.Log ("C key was pressed");
SwitchCam ();
}
}
Well I tried this code as I wish for more than one camera in my game I want lots as I want to be able to see from both friendlies and enemies but all I keep getting when I run this code is this
Blockquote
: Error CS0116: A namespace cannot directly contain members such as fields or methods (CS0116) (Assembly-CSharp)