- Home /
Aiming-recoil animation problem
Hello:) I have got a problem with my script.I've got 2 animations, one is for normal shooting and second is for aim shooting.But no one is working :( Here is my script:
var Bullet : Transform;
var Spawn : Transform;
var shot : AudioClip;
var fireRate : float = 1.0;
private var nextFire : float = 0.0;
private var t : Transform;
var isReloading = false;
var reloadTime = 1.5;
var ammoCount = 20;
var ammoInMagazine = 20;
var clips = 5.0;
var currentBullets = 20;
var reload : AudioClip;
var aiming = false;
function Start () {
t = transform;
}
function Update () {
if (Input.GetButton("Fire1") && IsOkToShoot()) {
Shoot();
if(Input.GetButton("Fire3") && aiming == false){
aiming = true;
animation.Play("shooting");
}
if(Input.GetButton("Fire3") && aiming == true) {
aiming = false;
animation.Play("hip");
}
}
}
function IsOkToShoot () : boolean {
var itsOk : boolean = false;
if (Time.time>nextFire) {
nextFire = Time.time + fireRate;
itsOk = true;
}
return itsOk;
}
function Shoot() {
//only shoot if you have ammo.
if (currentBullets > 0) { // <-- Need curly or only one line of code is invoked.
var pel = Instantiate(Bullet, Spawn.position, Spawn.rotation);
pel.rigidbody.AddForce(transform.forward * 20000);
AudioSource.PlayClipAtPoint(shot, t.position);
currentBullets--; //subtract one
}
if (currentBullets <= 0){
audio.Play();
Reload();
}
}
function Reload() {
// Wait for reload time first - then add more bullets!
yield WaitForSeconds(reloadTime);
if (clips > 0) {
clips--;
currentBullets = ammoInMagazine;
}
}
*Sorry for my bad English.I'm from Czech republic.Thank you for any response :)
Comment
Your answer
Follow this Question
Related Questions
FPS Shoooting Problem 1 Answer
Make Camera and Character Face Same Direction 1 Answer
Help with a Script in C# for shooting and lighting 1 Answer
Gun shooting and ammo problem 1 Answer
2D Aiming and Shooting at the mouse 3 Answers