I have already referred the animator by using the statement,
But,What is the use of getcomponent in awake() function.What happens without it.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
Animator anim; is just a empty reference. If you want to actually access the
Animator script attached to the object, you'll have to use
GetComponent<Animator>() and assign it to
Your first sentence is incorrect
Animator anim; does not refer to anything. It's simply a placeholder for referencing an
Animator object. It doesn't point to anything unless you tell it what to point to.
if you make a public variable like
public Animator anim;
in a monobehavior script, outside any method, you can drag and drop a gameobject with animator component in inspector when you add this script to a gameobject. it will automatically get the Animator component from the dropped gameobject.
But if you already have a reference to the desired gameobject(g) with a Animator component, you can get a reference to it by