- Home /
on trigger Enter
when i use of below code,it's will not trigger with the rightBox other world the (OnTriggerEnter)function isn't work.i used of debug.log for ensure that.
using UnityEngine; using System.Collections;
public class boxScript : MonoBehaviour { public int speed = 2; bool done; // Use this for initialization void Start () { done=true; } // Update is called once per frame void Update () { if(done==true) { transform.Translate(Vector3.right*Time.deltaTime*speed); } } void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "rightBox") { done=false; Debug.Log ("trigged"); transform.Translate (Vector3.left*Time.deltaTime*speed); } if(other.gameObject.tag == "leftBox") { transform.Translate (Vector3.right*Time.deltaTime*speed); } } }
Answer by Montraydavis · Oct 14, 2012 at 04:07 PM
Be sure that it has both a collider, and RIGIDBODY .