Question by
MrNemesis131 · Jun 16, 2016 at 01:13 AM ·
javascriptsound on key
play sound on button enter in javascript
hey guys I'm a big noob in unity and I am trying really hard to learn but I don't know how to trigger sound on movement key entry any help could be really helpful
#pragma strict
var forwardRate : float = 5;
var turnRate : float = 90;
var player:boolean;
function Update ()
{
// tank's forward speed in action
var forwardMoveAmount = Input.GetAxis("Vertical1") * forwardRate;
// force of the tank's turn
var turnForce = Input.GetAxis("Horizontal1") * turnRate;
// rotate tank in action
transform.Rotate(0,turnForce,0);
transform.position += transform.right * forwardMoveAmount * Time.deltaTime;
}
Comment
Answer by KuR5 · Jun 16, 2016 at 06:53 AM
Hi,
As per my understanding on your question, you can check values of Input.GetAxis("Vertical1") and/or Input.GetAxis("Horizontal1") and if it is not zero then you can play the sound.
Your answer
![](https://koobas.hobune.stream/wayback/20220612083031im_/https://answers.unity.com/themes/thub/images/avi.jpg)