- Home /
Gameobject.transform.Translate not working
This is my code:
import System.Collections.Generic;
var timer: float = 300; // set duration time in seconds in the Inspector
var cubeArray = new List.<GameObject>();
var cubes: int;
function Start() {
}
function Update(){
timer -= Time.deltaTime;
if (timer < 0){
timer = 5;
cubes = 0;
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent(CubeScript);
cube.transform.position = Vector3 (0, 30, 0);
cubeArray.Add(cube);
for (selectedCube in cubeArray) {
cubes++;
selectedCube.transform.renderer.material.color = Color.red;
selectedCube.transform.Translate(Vector3.down * Time.deltaTime);
}
} else {
guiText.text = timer.ToString("F1") + " " + cubes.ToString("F0");
}
}
For some reason, the cubes dont move down, but they do turn red. I'm lost on what to do next, could somebody tell me what to do?
Answer by Eric5h5 · Jun 03, 2013 at 02:41 PM
They do move, but not much...you shouldn't use Time.deltaTime in Translate if you're doing it once every 5 seconds. You use Time.deltaTime when you're moving something every frame.
Thank you for helping me fix the problem.
Also, how would I transform.translate unless there is something in the way?
Or should I post that in a separate question?
Your answer
Follow this Question
Related Questions
Rigidbody Sink into BoxColider 0 Answers
Moving character on x axis 1 Answer
Dont transform.translate if it will collide with another object 1 Answer
How can I instantiate and move objects smoothly? 1 Answer
force traslation 1 Answer