Cannot access an animation from script

by StuckInPhD   Last Updated November 09, 2018 01:13 AM

I want to change the reload speed of my player when a button is pressed in the pause menu.

I created a button and attached the following script to it (as suggested by the documentation here: https://docs.unity3d.com/ScriptReference/AnimationState-speed.html ):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseUpgrade : MonoBehaviour {

public Animation reloadAnim;
private float startSpeed;
// Use this for initialization
void Start () {
    startSpeed = reloadAnim["Reloading"].speed;
}

public void upgradeSpeed()
{
    reloadAnim["Reloading"].speed += 0.5f;
}

But this does not work. I cannot seem to drag the reload animation into the public variable declared above. Is this the correct way to solve this?

Thanks

Tags : unity animation


Related Questions


Updated February 16, 2018 23:13 PM

Updated March 17, 2016 08:05 AM

Updated August 27, 2018 17:13 PM

Updated June 01, 2015 17:05 PM