- Home /
transform.Translate on +y and -Y
hello guys , i want to make the cube translate on y and after 10 seconds translate on -y and still repeating it . hoe i make it repeat every 10 seconds up and down up and down ....sorry for my english
Yspeed=2;
function Update () {
transform.Translate(0,0.03*Time.deltaTime*Yspeed,0);
transform.Translate(0,-0.03*Time.deltaTime*Yspeed,0);
}
Comment
Best Answer
Answer by NoseKills · Jun 25, 2014 at 10:53 PM
#pragma strict
var Yspeed:float = 2;
var changeIntervalSeconds:float = 10;
var timer:float = 0;
var direction:int = 1;
function Update ()
{
timer += Time.deltaTime;
if (timer > changeIntervalSeconds)
{
direction = -direction;
timer = 0;
}
transform.Translate(0, 0.03 * Time.deltaTime * Yspeed * direction,0);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613152520im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make a object translate alonge an other 2 Answers
Can't move instantiated prefab 2 Answers
How do I duplicate an object to work with a shootemup 0 Answers
Camera transform not responding after load 0 Answers
transform.Translate tutorial question 2 Answers