- Home /
Gun Recoil Help
I am working a First Person Shooter game, and I have been messing around in Unity for a couple of months or so. I have my gun and I want to add recoil, making the game step-by-step. So I added the following script to add recoil and attached it to my gun gameObject, however, when I left mouse click, nothing happens. What is wrong with the script and maybe could someone point me in the right direction? Thanks in advance.
function OnMouseDown() {
if(Input.GetMouseButtonDown(0)) {
gameObject.transform.Translate(Vector3.back * 1 * Time.deltaTime);
yield WaitForSeconds(1);
gameObject.transform.Translate(Vector3.forward * 1 * Time.deltaTime);
}
}
I have also tried it like this...
if(Input.GetMouseButtonDown(0))
gameObject.transform.Translate(Vector3.back * 1 * Time.deltaTime);
yield WaitForSeconds(1);
gameObject.transform.Translate(Vector3.forward * 1 * Time.deltaTime);
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How To Set Scope Speed 2 Answers
new to scripting need some fps controll help plz :) 2 Answers
Specs to keep whie making a PC game? 2 Answers
what is wrong with this online FPS script(not done) ? 1 Answer