- Home /
Question by
francedema · Jul 21, 2012 at 11:25 AM ·
gameobjecttriggergetcomponent
BCE0019: 'cont' is not a memBCE0019: 'cont' is not a member of 'UnityEngine.Component'. ber of 'UnityEngine.Component'.
hi guys... I have a problem whit this exception at this line:
var trigger=GameObject.Find("Macchina"); var continua=trigger.GetComponent("GestioneTrigger").cont;
I have previously created the script "GestioneTrigger", and inside there is only a boolean variable. My goal is to take the boolean variable from another script but I have this exception.
Comment
Answer by fafase · Jul 21, 2012 at 11:27 AM
Try like this:
var trigger=GameObject.Find("Macchina");
var continua:GestioneTrigger =trigger.GetComponent(GestioneTrigger);
continua.cont;
The simple/short answer is, don't use strings in GetComponent ;). That way the compiler can't deter$$anonymous$$e the type that is returned by GetComponent. When using a type, the compiler will return the correct reference type (in your case a GestioneTrigger reference).