- Home /
OP found the solution himself.
[C#]OnTriggerExit set Collided false ???
I'm currently working on a game like total war, i made a simple stop when it collides with something script but now I want the unit to move forward when the object exit the trigger my unit moves forward unitil he collides with a object.
my script
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(Rigidbody))]
public class UnitAI : MonoBehaviour {
public bool Selected = false;
public GameObject selectedCirkle;
public float health = 10;
public bool Collided = false;
public float moveSpeed= 20;
public float stopSpeed = 0;
// Use this for initialization
void Start () {
selectedCirkle.SetActive (false);
}
// Update is called once per frame
void Update () {
if (Selected == true && Collided == false) {
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
if (Selected == true && Collided == true) {
transform.Translate(Vector3.forward * stopSpeed * Time.deltaTime);
}
}
void OnTriggerEnter (Collider other){
if (other.tag == "Unit") {
Collided = true;
}
}
void OnTriggerExit (Collider other){
Collided = false;
}
void OnMouseDown () {
Selected = true;
selectedCirkle.SetActive(true);
}
}
~Dragon_Developer
You should specify your onTriggerExit other.
if (other.tag == "Unit") Collided = false;
Answer by Dragon_Developer · Aug 26, 2014 at 12:22 PM
nope still the same nevermind i fixed it already i forget to put a rigidbody component on the collidable object
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
AI in unity, need help 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
Enemy ai Multiple targets 1 Answer