Code (JavaScript): import UnityEngine.Audio; static var ammo = 9; static var maxAmmo = 9; var key : String = "mouse 0"; var bullet : Rigidbody; var speed : float = 1000; var bulletSound : AudioClip; var soundofgun : GameObject; var gun : GameObject; var ani : Animation; function Start () { ani = GetComponent ("Animation"); } function Update () { if(Input.GetKeyDown(key)){ if(ammo > 0){ shoot(); } } if(Input.GetKeyDown("r")){ ammo = 9; ani.Play("reload"); } } function shoot(){ var bullet1 : Rigidbody = Instantiate(bullet, transform.position, transform.rotation); bullet1.AddForce(transform.forward * speed); soundofgun.GetComponent.<AudioSource>().Play(); ammo --; } function OnGUI(){ GUI.Label(Rect(10, 10, 500, 500), "Gun ammo "+ammo); } it doesnt play the animation, please help Note: animation is atached and its marked as a legacy animation, no controller
Input.GetKeyDown doesn't work on mouse buttons, just keyboard. You're looking for Input.GetMouseButtonDown, or Input.GetButtonDown if you want to set it up in the input manager. It's case sensitive as well. "mouse 0" is not "Mouse 0". I'd also recommend using the KeyCode version of GetKey instead of the string version - it's harder to make small mistakes. Also, in the future, please be more descriptive with your subject line. Every post here is a programming problem.