MiniScript is a simple yet powerful scripting language embedded in URT3D assets. Use it to define how your asset behaves on load, when interacted with, or in response to custom events.
Below are ready-to-use MiniScript examples categorized by behavior type.
๐ Animation Control
Play an animation when the asset loads:
anim = GetTrait("Animatable")
function OnStart()
anim.PlayAnimation("Idle", true)
end function
Switch animations based on custom events:
anim = GetTrait("Animatable")
function OnCustomEvent(name)
if name == "Jump" then
anim.PlayAnimation("Jump", false)
else if name == "Walk" then
anim.PlayAnimation("Walk", true)
end if
end function
๐ Interaction Handling
Respond to a click with a toggle effect:
interactable = GetTrait("Interactable")
active = false
function OnStart()
interactable.OnClick = OnClick
end function
function OnClick()
active = not active
Print("Clicked! State = " + active)
end function
โฑ๏ธ Time-Based Behavior
Delay an animation:
anim = GetTrait("Animatable")
function OnStart()
Delay(2)
anim.PlayAnimation("Reveal", false)
end function
Use Update() for floating hover effect:
interactable = GetTrait("Interactable")
position = GetTrait("Position3d")
originalY = position.GetValue().y
hovering = false
function OnStart()
interactable.OnHoverEnter = OnHoverEnter
interactable.OnHoverExit = OnHoverExit
end function
function OnHoverEnter()
hovering = true
end function
function OnHoverExit()
hovering = false
end function
function Update()
pos = position.GetValue()
if hovering then
pos.y = originalY + 0.2 * Math.Sin(Time.Now * 5)
else
pos.y = originalY
end if
position.SetValue(pos)
end function
๐ Event Messaging
Trigger an event on another asset:
function OnClick()
TriggerEventOn("Play_Idle", "npc_001")
end function
๐งช State Control
Track and reduce health on a custom event:
health = 100
function OnCustomEvent(eventName)
if eventName == "Damage" then
health = health - 10
Print("Health = " + health)
end if
end function