when i use of below code,it’s will not trigger with the right box.in 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);
}
}
}