- Home /
My object wont move when I use transform.translate.
using UnityEngine;
using System.Collections;
public class ScriptedRunning : MonoBehaviour {
private float deleteTime = 4.0f;
void Start () {
}
void Update () {
}
void OnTriggerEnter(Collider col){
if(col.gameObject.name == "Player"){
if(!audio.isPlaying)
audio.Play();
transform.Translate(0,0,6f * Time.deltaTime);
Destroy(gameObject, deleteTime);
}
}
}
Answer by OmarAlhaddad · Feb 20, 2013 at 06:42 AM
OnTriggerEnter gets called once per trigger collision, thus making Translate to get called maybe once only (moving your object a tiny bit), if you want Translate to be called every frame you need to move it in the Update function.
Good luck
thanks it worked when i put it in the update function. Thanks
Answer by robertbu · Feb 20, 2013 at 06:45 AM
I'm not sure how far you think it should translate, but you only translating it about 0.1. (6.0 * 1/60). In addition you call Destory() on the same game object this script is attached to, so another frame is not displayed (and therefore you don't see movement).
Your answer
![](https://koobas.hobune.stream/wayback/20220613093033im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving object to specific location 1 Answer
Move object, then destroy it. 1 Answer
Moving an object to a specific location 1 Answer
Audio sound on gameObject delete? 1 Answer