- Home /
How to make Reloading animation play ONCE
hey guys I am making an FPS game and i reached the level where i make the reloading animations So, I have a boolean and whenever this boolean comes true my reloading animation and sound takes place. Unfortunately I have made a mistake on my scripting so that boolean never goes false as a result my animation never stops playing and i can't continue playing. I have tried to set the wrapMode to ONCE but nothing happends it continues playing like loop. I also tried to make the wrapMode.Once through scripting but also NOTHING happends my animation never stops playing. I have posted my script, let me know if I have skipped any information you may need to troubleshoot my problem.
Here is my script:
public int currentClip = 6;
public int currentExtraAmmo = 12;
public int maxExtraAmmo = 24;
public int clipSize = 6;
public bool reloading;
//Animations
public void AnimationController()
{
//JUMP ANIMATIONS
if(wasStanding && !CharCont.isGrounded)
{
wasStanding = false;
WalkAnimationHolder.animation.Play("Jump");
}
else if (!wasStanding && CharCont.isGrounded)
{
wasStanding = true;
WalkAnimationHolder.animation.Play("JumpLanding");
}
//RUNNING ANIMATIONS
if(walkingstate == WalkingState.Running)
{
WalkAnimationHolder.animation["Run"].speed = VelocityMagnitude / RunSpeed * 1.2f;
WalkAnimationHolder.animation.CrossFade("Run", 0.2f);
}
//WALKING ANIMATION
else if (walkingstate == WalkingState.Walking && !reloading)
{
WalkAnimationHolder.animation["Walk"].speed = VelocityMagnitude / WalkSpeed * 1.2f;
WalkAnimationHolder.animation.CrossFade("Walk", 0.2f);
}
//RELOADING ANIMATION WHILE WALKING
else if (walkingstate == WalkingState.Walking && reloading == true)
{
WalkAnimationHolder.animation["Reload"].wrapMode = WrapMode.Once;
WalkAnimationHolder.animation.CrossFade("Reload");
}
//RELOADING ANIMATION WHILE STAYING PUT
else if (walkingstate == WalkingState.Idle && reloading == true)
{
WalkAnimationHolder.animation["Reload"].wrapMode = WrapMode.Once;
WalkAnimationHolder.animation.CrossFade("Reload");
}
//IDLE ANIMATION
else
{
WalkAnimationHolder.animation.CrossFade("Idle", 0.2f);
}
}
//Shoot Station
public void ShootController()
{
//RELODING LOGIC
if(currentClip > clipSize)
currentClip = clipSize;
if(currentExtraAmmo > maxExtraAmmo)
currentExtraAmmo = maxExtraAmmo;
if(currentClip < 0)
currentClip = 0;
if(currentExtraAmmo < 0)
currentExtraAmmo = 0;
//RELOADING BUTTONS AND ACTIONS
if(!reloading && Input.GetButtonDown("Reload") && currentClip < clipSize && currentExtraAmmo > 0)
{
reloading = true;
}
//RELOADING BUTTONS AND ACTIONS
if(!reloading && Input.GetButtonDown("Fire1") && currentClip == 0 && currentExtraAmmo > 0)
{
reloading = true;
}
//STOPING THE ANIMATION AND RETURN false
if(reloading && !WalkAnimationHolder.animation.IsPlaying("Reload"))
{
if(currentExtraAmmo >= clipSize - currentClip)
{
currentExtraAmmo -= clipSize - currentClip;
currentClip = clipSize;
}
if(currentExtraAmmo < clipSize - currentClip)
{
currentClip += currentExtraAmmo;
currentExtraAmmo = 0;
}
reloading = false;
}
//BASIC SHOOTING SYSTEM + RECOIL + SOUND
if (Input.GetButtonDown("Fire1") && currentClip > 0 && !reloading)
{
if (shoottime <= Time.time)
{
shoottime = Time.time + CurrentWeapon.firerate;
CurrentRecoil1 += new Vector3(CurrentWeapon.RecoilRotation.x, Random.Range(-CurrentWeapon.RecoilRotation.y, CurrentWeapon.RecoilRotation.y));
CurrentRecoil3 += new Vector3(Random.Range(-CurrentWeapon.RecoilKickback.x, CurrentWeapon.RecoilKickback.x), Random.Range(-CurrentWeapon.RecoilKickback.y, CurrentWeapon.RecoilKickback.y), CurrentWeapon.RecoilKickback.z);
}
GameObject inst_bullet = Instantiate(CurrentWeapon.Bullet, CurrentWeapon.Spawnpoint.position, CurrentWeapon.Spawnpoint.rotation) as GameObject;
inst_bullet.rigidbody.AddRelativeForce(Vector3.forward, ForceMode.Impulse);
Physics.IgnoreCollision(inst_bullet.collider, CharCont);
currentClip -= 1;
if (bulletSound)
{
holdSound = Instantiate(bulletSound, CurrentWeapon.Spawnpoint.transform.position, CurrentWeapon.Spawnpoint.transform.rotation) as GameObject;
}
if (holdSound)
{
holdSound.transform.parent = transform;
}
}
}
Your answer
Follow this Question
Related Questions
Death animation play more than once 1 Answer
AI function/coroutine animation issues 2 Answers
Wrap Mode in animator not working properly 0 Answers
Once Animation Wrapmode v4.3.3 0 Answers
Animation Wrap Mode Usage? 1 Answer