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: ):

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?


Tags : unity animation

Related Questions

Updated February 16, 2018 23:13 PM

Updated April 15, 2019 06:13 AM

Updated March 17, 2016 08:05 AM

Updated August 27, 2018 17:13 PM