Hello.
I’m having difficulty getting the Audio Listener component to enable/disable in correspondence with the camera switch. Error CS0119: Expression denotes a type, where a variable, value or method group was expected.
Here’s my code.
using UnityEngine;
public class CameraSwitch : MonoBehaviour
{
public GameObject camera1;
public GameObject camera2;
void Start()
{
camera1.SetActive(true);
camera1.GetComponent(AudioListener).enabled = true;
camera2.SetActive(false);
camera2.GetComponent(AudioListener).enabled = false;
}
void Update()
{
if (Input.GetButtonDown("ButtonA") || Input.GetKeyDown("1"))
{
camera1.SetActive(true);
camera1.GetComponent(AudioListener).enabled = true;
camera2.SetActive(false);
camera2.GetComponent(AudioListener).enabled = false;
}
if (Input.GetButtonDown("ButtonY") || Input.GetKeyDown("2"))
{
camera1.SetActive(false);
camera1.GetComponent(AudioListener).enabled = false;
camera2.SetActive(true);
camera1.GetComponent(AudioListener).enabled = true;
}
}
}
It seems pretty straightforward, which is why I can’t understand why this error is occurring. Many thanks for the assist!
Jonathan