I think I am doing right, but I have "Object reference not set to an instance" error.
I have GolfDrive GameObject. Then Golf_drive2 animation is put under it. As shown in the first image.
Then I have a variable currentObject in my script and set Golf_drive2 to control the animation. As shown in the second image.
When I tried to access the animation as follow
var frame = currentObj.GetComponent<Animation>()[currentObj.name].time;
I have "Object reference not set to an instance of an object".
What could be wrong?
EDIT: I changed as
var frame = 1.2f;
if (currentObj != null)
frame = currentObj.GetComponent<Animation>()[currentObj.name].time;
That means currentObj is not null. Then still have the same error.
EDIT 2: I tested the animation as
Animation n = currentObj.GetComponent<Animation>();
if (n == null)
Debug.Log("I AM NULL");
Nothing is printed, so animation is not null.

