There are two main ways I am aware of to modify an attached component.
Say, the component attached to an object is of type Animator
and the name is animator
.
So, in the script, I can write
private Animator animator;
and then call the function
animator = GetComponent<Animator>();
Or, I can define the variable as public
public Animator animator
and then, drag&drop in the Unity UI. Which one is the better practice?