I have a ak 47 gun model with an reloading animation. I dont want the reloading animaation to start right when i start playing my game. I only want my gun to start reloading when i press the key "r". How do i do this? Do I need some sort of script or something?
well, a script would work, it would be something like:
function Update()
{
if(Input.GetKeyDown("r"))
{
// Plays the reload animation - stops all other animations
animation.Play("reload", PlayMode.StopAll);
}
}
just so you know, you have to rename the "reload" animation to whatever you called it.
hope this helps.
well guys this is what i did. i made the script and made a new input. I made a new javascript, called "reload", and copyed and pasted that script you gave me into it. Then copyed that script into my gun item thing. currently its in the hierarchy. my gun is also called "reload". i tried it and it didnt work. it kept saying: "the animtaion state reload could not be played because it couldnt be found!" so i tried the iput thing. i made a new input called reload. i put the postive key as "r". i tried it again and it didnt work. it said the same thing. "the animtaion state reload could not be played because it couldnt be found!" whats wrong? why cant it play it? why does it keep saying that? could some one help me?
Do as Unity3_User says but change (Input.GetKeyDown) to (Input.GetButtonDown)
This happened to me it was because the animation name had a capital ’ R’and the “reload” in the script doesnt. so check your capitals, this answer is for sam
How can I make this same affect apply for when I press a mouse button?
i used this method, works very efficiently thank you
Lets say I put
if(Input.GetKeyDown(“w,a,s,d”))
would the commas make the script work, if I press one of them?
This might be because you were not clicked on the gun when you did the animation. When you open the animation tab, make sure to have your gun selected in heirarchy, then hit record, animate it, name it,and it should be there in your project tab. Then all you have to do is apply the script to the gun, and it should work.