Then I change the range/mute properties and want to reassign them to the player. I am doing this by:
player.audio = step;
player.light = flashlight;
but I get the error “UnityEngine.GameObject.audio cannot be assigned to (it is read only)” Does the Update() function do this for me? Or am I doing something wrong? Thanks in advance
You’re positively doing something wrong: the properties audio and light are read-only, they only have the references to the corresponding components - you must instead modify the component properties in each case.
If you want to select a different sound for each step, for instance, you should do something like this:
public AudioClip[] footsteps; // assign the step sounds to this array in the Inspector
void PlayFoostep(){
// randomly select one of the step sounds:
player.audio.clip = footsteps[Random.Range(0, footsteps.Length)];
// play it:
player.audio.Play();
}
For the flashlight, you can change the appropriate properties, like color, intensity etc.