- Home /
Reload FPS Animation Not Playing (Javascript)
Ok so i have my shoot script and everything works fine but when i reload it plays first couple frames then cuts. then has 3.3 reload time and adds bullets back but without the animation.
//Gun Stats
var Damage : float;
var Range : float = 1000;
var Force : float = 500;
var Clips : int = 2;
var BulletsPerClip : int = 12;
var ReloadTime : float = 3.3;
var BulletsLeft : int = 0;
var ShootTimer : float = 0;
var ShootCooler : float = 0.6;
public var ShootAudio : AudioClip;
public var ReloadAudio : AudioClip;
var Aiming: boolean = false;
var Gun : GameObject;
function Start(){
BulletsLeft = BulletsPerClip;
}
function Update () {
if (ShootTimer > 0){
ShootTimer -= Time.deltaTime;
}
if(ShootTimer < 0){
ShootTimer = 0;
}
if(Input.GetMouseButtonDown(0) && BulletsLeft)
{
if(ShootTimer ==0){
RayShoot();
PlayShootAudio();
ShootTimer = ShootCooler;
}
}
if (Input.GetMouseButtonUp(1))
{
Aiming = false;
}
if (Input.GetMouseButtonDown(1))
{
Aiming = true;
}
}
function RayShoot () {
if(Aiming == true){
Gun.animation.Play("ShootingAiming");
}
else if(Aiming == false){
Gun.animation.Play("ShootingIdle");
}
var Hit : RaycastHit;
var DirectionRay : Vector3 = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if(Physics.Raycast(transform.position , DirectionRay , Hit , Range)){
if(Hit.rigidbody) {
Hit.rigidbody.AddForceAtPosition(DirectionRay * Force, Hit.point);
}
}
BulletsLeft --;
if(BulletsLeft <0){
BulletsLeft = 0;
}
if(BulletsLeft == 0){
Reload();
}
}
function Reload() {
PlayReloadAudio();
Gun.animation.Play("Reload", PlayMode.StopAll);
yield WaitForSeconds(ReloadTime);
if(Clips > 0){
BulletsLeft = BulletsPerClip;
}
}
function PlayShootAudio(){
audio.PlayOneShot(ShootAudio);
}
function PlayReloadAudio(){
audio.PlayOneShot(ReloadAudio);
}
That probably has more to do with the animation then your script. Use the animation window to preview the animation you have and see if it's the same as it is when you click play :)
Can it be another animation that steps over this one ? Like a layer problem for example if you use the Add$$anonymous$$ixingTransform method ?
In line 89 it states:
Gun.animation.play("Reload", Play$$anonymous$$ode.StopAll)
Because play "Reload" is the first argument, it is executed first. Right after the animation is asked to play you stop all animations with the second argument. Perhaps you should stop all animations first and then play "Reload"
The documentation on Play$$anonymous$$ode.StopAll
specifically states "Stops all animations before playing". That should not be the cause of the problem
Answer by Weirdo-Studios · Jul 07, 2013 at 11:32 AM
Ok so i solved this i just changed the layer the reload played on.
Your answer
Follow this Question
Related Questions
Switch Weapon Script Not taking effect HELP!! 2 Answers
script for animation play 1 Answer
Reload Animation 0 Answers
Reload animation.... magazine hiding 0 Answers