How to change speed of animation in C#

I have an animation clip called “slideAnimClip” which runs perfectly when I play the game. However it’s a prefab and I want many of these to be on the screen running at different speeds depending on circumstance.

Here is my script

using UnityEngine;
using System.Collections;

public class slideBangScript : MonoBehaviour {
	
	public float animSpeed = 1f;
	public Animation anim;

	void Update () {
	Animation["slideAnimClip"].speed = animSpeed;
	}
}

I think this should be correct, but I keep getting this error:

Assets/Scripts/slideBangScript.cs(12,9): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

I’d be extremely grateful for any help.

Thanks.

1 Answer

1

Change

Animation["slideAnimClip"].speed = animSpeed;

to

anim["slideAnimClip"].speed = animSpeed;

Animation is a type, while anim is your member method that is an instance of that type.