GetAnimationClipDurationOfPrefabInstance

Definition

double GetAnimationClipDurationOfPrefabInstance(string prefabInstanceName, string animationClipName)

Description

This function returns the time of animationClipName animation of the prefab instance prefabInstanceName.

Parameters

prefabInstanceName
Specifies the name of the prefab instance. You can also use the name “this” for this parameter. In this case, “this” refers to the prefab instance that this script is attached to.

animationClipName
Specifies the name of the prefab instance animation. To view the name of the prefab instance animations, you can go to the Modify > Properties menu in the prefab editor, or select the name of the prefab instance from the Prefabs and GUIs section in the current VScene and press the Edit button.

Return Value

Returns the time of animationClipName animation of the prefab instance prefabInstanceName.

Example 1

animationTime = 0.0

function Init()
    animationTime = GetAnimationClipDurationOfPrefabInstance("1_animation_test_boy""defaultClip")
    message = string.format("\nanimation duration is > %.2f" ,animationTime )
    PrintConsole(message)
end

function Update()

end
In this case, GetAnimationClipDurationOfPrefabInstance returns the the time of “defaultClip” animation of the prefab instance “1_animation_test_boy”. Then we print the return value of this function. The result would be something like this message:
animation duration is > 12.50

Example 2

--name of this script is GetAnimationClipDurationOfPrefabInstance2.lua

animationTime = 0.0

function Init()
    animationTime = GetAnimationClipDurationOfPrefabInstance("this""defaultClip")

    message = string.format("\nanimation duration is > %.2f" ,animationTime )
    PrintConsole(message)
end

function Update()

end
If, in the Prefab Editor, you attach GetAnimationClipDurationOfPrefabInstance2.lua script to a Prefab that has “defaultClip” animation, then “this” parameter in the GetAnimationClipDurationOfPrefabInstance function will point to instances of that Prefab in current VScene. For example, if you have an Instance named instance1_a from a Prefab named to which this script is attached, “this” in GetAnimationClipDurationOfPrefabInstance function refers to the name instance1_a.
In this case, GetAnimationClipDurationOfPrefabInstance function returns the time of “defaultClip” animation of Prefab Instance instance1_a.
adminGetAnimationClipDurationOfPrefabInstance