how would i slow this animation

hello again ive done a rewrite of my previous weapon script so i could think it through and ive run into a snag, i want to decrease the speed of my reload animation if the player doesent press r before running out of bullets in the guns mag but the snag is that im new to coding, been doing it for two slow months learned a lot

so heres the code it mostly works but a s i said i want to slow the reload animation

using UnityEngine;
using System.Collections;

public class Weaponcontrol : MonoBehaviour {

public bool Hasammo = !false;
public int Maxrounds = 17;
public int Currounds = 17;
public GameObject Gun;
public float Playspeed = 1.0f;
public Animation Fire;
public Animation Reload;

	void Start () { 
	
		Fire =  Gun.animation.GetComponent (Fire.animation);
		Reload =  Gun.animation.GetComponent (Reload.animation);
	}
	
	

	void Update (){  
	
			if (Input.GetMouseButtonDown(0));
				{   
				Hasammo = !false;
				}
				
				Gun.animation.Play (Fire);
				Currounds-=1;
				
					if (Hasammo = false);
					{
					
					Gun.animation.Play (Reload);
					}
		animation[Reload].speed = Playspeed   //i want to take a a quater off playspeed and set the remainder to the animation speed as a float
					
					Currounds = Maxrounds;
					
					
		if (Currounds <= 0){
		
			Hasammo = false;
			
			}   
			else
			{  
			
			Hasammo = !false;
			
			if(Input.GetKeyDown(KeyCode.R)){
			Gun.animation.Play(Reload);
			  Currounds = Maxrounds;
			}
		}
	}
}

its changed a lot from my last question whats the bet way to do this

as requested here are the pics [33767-unity+1.png|33767]

and [33768-unity+2.png|33768]

sorry it took a few hours

The problem seems to be that you’re never reinitializing the animation speed.

 animation[Reload].speed = Playspeed*0.75f; 

that line is fine, it does what you want.
-EDIT Wrong, I’m sorry, I should have read the whole code above. a string should be inside the brackets, I assumed Reload was a string

But you need to set it back to normal speed when it’s reloading the “other” way.

An easy way to do this without having to keep track of what the speed is at, is actually having 2 speed variables.

float SlowReloadSpeed = 0.75f;
float NormalReloadSpeed = 1.0f;

So, In one case, you’re changing the speed to the slow one, then firing the animation. In the other, you change it to the normal speed, then fire the animation.

Oh, you might want to change the speed BEFORE launching the animation.


Edit -

I’m sorry, I missed a lot of errors in the above code. You seem to be confusing Animation with AnimationClips

Basically, An animation is a collection of AnimationClips.

I’m not sure how your animations are setup… Are they 2 clips inside the same animation ? or 2 animations with a single clip in them ?

In any case, you need the clip’s name to play a specific animation, or change some of their parameters (such as the speed)

If an animation contains a single clip, then you can just use it like so :

MyAnim.Play();

but if it contains more than one, I don’t know exactly what would happen with the above call, But you can get it to play a specific animationClip if you specify a name in the call.

MyAnim.Play("reload");

Now, when setting speed, You will need the animation clip’s name. And make the call like so :

MyAnim["clipName"].speed = 0.75f;

Edit 2-

    public bool hasAmmo = true;
	public int maxRounds = 17;
	public int curRounds = 17;
	public GameObject gun;
	public float slowReloadSpeed = 0.75f;
	public float normalReloadSpeed = 1.0f;
	public string fireAnim;
	public string reloadAnim;
	
	void Update()
	{  
		if (!gun.animation.IsPlaying(reloadAnim) && !gun.animation.IsPlaying(fireAnim))
		{
			if (Input.GetMouseButtonDown(0))
			{
				if (hasAmmo)
				{
					gun.animation.Play(fireAnim);
					curRounds -= 1;
				}
				else
				{
					animation[reloadAnim].speed = slowReloadSpeed;
					gun.animation.Play (reloadAnim);
					curRounds = maxRounds;
				}
			}
		
			if(Input.GetKeyDown(KeyCode.R))
			{
				animation[reloadAnim].speed = normalReloadSpeed;
				gun.animation.Play(reloadAnim);
				curRounds = maxRounds;
			}
		}
		hasAmmo = (curRounds > 0);
	}