Hi,
i get a null reference exception because i set .enabled of a public collider inside a property. I did a workaround and return if the collider is null, but i wonder why the error occurs and if there isn’t any better way to solve it?
using UnityEngine;
using System.Collections;
public class BaseClass : MonoBehaviour {
public Collider col;
bool isColliderActive;
BaseClass(){
IsColliderActive = false;
}
bool IsColliderActive{
get{
return isColliderActive;
}
set{
isColliderActive = value;
col.enabled = isColliderActive;
// NullReferenceException: Object reference not set to an instance of an object
// This error msg appears three times before the collider seems to be loaded
}
}
}