I’m trying to make a working lightswitch on mouseclick in unity 5. I’m getting compiler errors. This is the script:
using UnityEngine;
using System.Collections;
public class LightSwitch : MonoBehaviour
{
public light light;
public GameObject goLightSwitch;
public AudioClip SwitchOn;
public AudioClip SwitchOff;
private bool switchOn;
private GameObject _UpPosition;
private GameObject _DownPosition;
private AudioSource _audioSource;
void Awake()
{
_upPosition = GameObject.find("UpPosition");
_downPosition = GameObject.find("DownPosition");
_audioSource = gameobject.GetComponentInChildren<AudioSource>();
}
void OnMouseDown()
{
if (_switchOn)
{
_switchOn = false;
goLightSwitch.transform.position = newVector3(goLightSwitch.transform.position.x, _downposition.y, goLightSwitch.transform.position, z);
Light.enabled = false;
_audioSource.clip = SwitchOff;
_audioSource.play();
}
else if (_switchOn)
{
_switchOn = true;
goLightSwitch.transform.position = newVector3(goLightSwitch.transform.position.x, _upposition.y, goLightSwitch.transform.position, z);
Light.enabled = false;
_audioSource.clip = SwitchOn;
_audioSource.play();
}
}
}
The Microsoft visual editor isn’t registering any errors,but when I try to use it I get this error message in the game:
Assets/LightSwitch.cs(6,12): error CS0118: LightSwitch.light' is a field’ but a `type’ was expected
I am extremely new to c# and unity and I don’t know what I need to do to fix it. Can anyone tell me what I need to change and what to change it to? I’d really appreciate any help.