Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't set public variable.

Discussion in 'Animation' started by tlemo_, Dec 27, 2018.

  1. tlemo_

    tlemo_

    Joined:
    Dec 22, 2018
    Posts:
    5
    I'm trying to make a script that animates a gun (parented to the camera in an fps character).
    The problem is setting the public variable I'm using to reference the animation. It won't let me drag-and-drop the animation to the variable like most of the time.

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

    public class AnimationManager : MonoBehaviour {
    public Animator anim;
    public Animation Walk;
    // Update is called once per frame
    void Update () {
    if (Input.GetKey("w")){
    anim.Play(Walk.name);
    }
    }
    }


    I'm not too confident in using Walk.name either, it might be wrong.

    Things to point out:
    • The public reference is referring to an Animation, not an AnimationClip or Animator. The one that is referring to the Animator is already set.
    • I'm not experienced at C#, as I'm currently learning it.
    • The gun was obviously made in ProBuild.
    • The animation is not in the scene itself (I don't know how to do this, if I need to, please tell me how).
    This is another situation where I was stuck with answers to similar questions either complex or just unhelpful, hope this will go well!

    upload_2018-12-27_11-38-4.png
    The gun with the camera (the white blocks are low-poly arms).

    upload_2018-12-27_11-41-24.png
    The variables


    Footage of me trying to drag-and-drop the animation.
     
  2. Take a look at your console, it may have something to do with it.
     
  3. tlemo_

    tlemo_

    Joined:
    Dec 22, 2018
    Posts:
    5
    Tried, it has nothing but errors and warnings completely unrelated to the subject at hand.