i want to get a component value from the game object which collides with my trigger's object script. this is my code on the trigger:
void OnTriggerEnter (Collider obj){
if(obj.GetComponent<motor>().enabled == true){
passed = true;
}
}
and this is the error i get:
NullReferenceException: Object reference not set to an instance of an object
cp.OnTriggerEnter (UnityEngine.Collider obj) (at Assets/Scripts/cp.cs:15)
also when changing the code on the trigger:
motor mObj = obj.gameObject.GetComponent();
if(mObj != null){
//code here
Debug.Log("mObj not null");
}else{
Debug.Log("mObj is null");
}
it returns
mObj is null
but the parent obj does have that 'motor' script, other scripts in the car which enter the trigger can access it