I want to disable the collider of the object when I hide it. But now when it disappears, I go to the spot of the object and the event happens when I touches air! Should I just collider.enable = false
or should I add more things?
Here’s my code just for reference:
public string type;
public bool avail;
public float time;
public float appearTime;
public float disappearTime;
private Collider coll;
// Use this for initialization
void Start () {
coll = this.GetComponent<Collider> ();
time = Random.Range (1, 5);
if (time < 2) {
avail = false;
} else {
avail = true;
}
}
// Update is called once per frame
void Update () {
time -= Time.deltaTime;
if (time < 0f) {
ShowAndHide ();
}
}
void ShowAndHide(){
if (avail) {
time = disappearTime;
avail = false;
this.gameObject.GetComponent<Renderer> ().enabled = false;
coll.enabled = false;
}
else {
time = appearTime;
avail = true;
this.gameObject.GetComponent<Renderer> ().enabled = true;
coll.enabled = true;
}