- Home /
set child object position when playing the animation
Hi I'm new to unity.I want to create a game that when I press the button, the dice appears, plays the animation, and then disappears. After the dice is invisible, the character moves.
Now I have a problem. When the dice appears, how can I let the dice always be in front of of the character(not on the character's position) even the player turn right or left? dice is the child object of the player.
This is my script:
var target:Transform;
var dice : GameObject;
var script:DiceNumber;
var number:int;
function Start () {
dice.active = false;
script = GetComponent(DiceNumber);
}
function dicego(){
number = DiceNumber.num;
dice.active = true;
yield WaitForSeconds(1);
dice.active = false;
}
function Update () {
if (number==1){
animation["Throw1"].wrapMode = WrapMode.Loop;
animation["Throw1"].speed = 0.5;
animation.CrossFade("Throw1");
}
if (number==2){
animation["Throw2"].wrapMode = WrapMode.Loop;
animation["Throw2"].speed = 0.5;
animation.CrossFade("Throw2");
}
if (number==3){
animation["Throw3"].wrapMode = WrapMode.Loop;
animation["Throw3"].speed = 0.5;
animation.CrossFade("Throw3");
}
transform.localRotation = Quaternion.identity;
}
Comment