ExecuteNonCyclicAnimation

Definition

ExecuteNonCyclicAnimation(string prefabInstanceName, string animationClipName, float delayIn, float delayOut, float weightTarget, bool lock)

Description

This function execute an animation of prefab instance once, instead of repeating it.

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.

delayIn
Specifies when the animationClipName reaches the weightTarget weight. This value must be 0.0 or higher.

delayOut
Specifies the fade out time at the end of the animation, when the weight of the animation reaches 0. This value must be 0.0 or higher.

weightTarget
Specifies the final weight of the animation clip animationClipName. A value of 1 means full animation and a value of 0 means no animation. This value must be in the range (0.0,1.0]

lock
If this attribute is true, the animation will be locked at the last frame. For example, suppose you have a door animation and you want the door to remain open after the animation plays. In this case, you need to lock it in the last frame. Otherwise, after the animation ends, the door will return to the first state.

Note: delayIn + delayOut time must not be greater than the duration of animation animationClipName

Example 1

function Init()
    ExecuteNonCyclicAnimation("1_animation_test_boy""defaultClip", 0.5, 0.7, 1.0, false)
end

function Update()

end
In the first 0.5 seconds, the “defaultClip” animation value of prefab instance “1_animation_test_boy” goes from weight 0 to weight 1.0 (full animation). Then, 0.7 seconds before the end of the animation, the weight of the “defaultClip” animation starts to decrease, and at the end of the animation, its weight reaches zero. This animation is not locked in the last frame.

Example 2

--name of script is executenoncyclicanimation2.lua

animation = true

function Init()

end

function Update()
    if animation == true then
          ExecuteNonCyclicAnimation("this""run", 0.5, 0.6, 0.4, true)
          animation = false
    end
end
If, in the Prefab Editor, you attach executenoncyclicanimation2.lua script to a Prefab that has an animation clip “run”, then “this” parameter in the ExecuteNonCyclicAnimation 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 ExecuteNonCyclicAnimation function refers to the name instance1_a. In this case, In the first 0.5 seconds, the “run” animation value of prefab instance instance1_a goes from weight 0 to weight 0.4 (40% of animation “run”). Then, 0.6 seconds before the end of the animation, the weight of the “defaultClip” animation starts to decrease, and at the end of the animation, its weight reaches zero. This animation is locked in the last frame.
adminExecuteNonCyclicAnimation