I’m fairly new to Unity so I have some problems. So I need Help with some things.
I have been hacking around this Grounded variable for a while and finally got it working but now the audio only stops and doesn’t start playing any more when I touch the ground. also all my Keypresses override my old keypress (which is proably what stops the audio from restarting when touching the ground) for example:
-
I’m holding down the “w” key: audio starts playing (as it should)
-
while holding down the “w” key I start holding down the “d” key: *audio restarts from beginning
-
I then let go of the “d” while still holding the “w” key: audio stops
#pragma strict
var isGrounded : boolean = true;
var controller : CharacterController = GetComponent(CharacterController);
var Sound : AudioClip;function Start () {
}
function Update () {
if(!controller.isGrounded){
{
audio.clip = Sound;
audio.Stop();
}} else { if((Input.GetKeyDown("w")||Input.GetKeyDown("a")||Input.GetKeyDown("s")||Input.GetKeyDown("d")) && isGrounded) { audio.Play(); } if((Input.GetKeyUp("w")||Input.GetKeyUp("a")||Input.GetKeyUp("s")||Input.GetKeyUp("d")) && isGrounded) { audio.Stop(); }
}
}
I hope somebody can help.
Thanks in advance!