What am I missing? Works in Unity, but not iPhone. Help please
function OnControllerColliderHit(hit : ControllerColliderHit) {
var crosshair = GameObject.FindWithTag (“crosshairs”);
crossTexture = crosshair.GetComponent(GUITexture);
if(hit.gameObject.tag == “Base”) {
crossTexture.MonoBehaviour.enabled = true;
}
else {
crossTexture.enabled = false;
}
}
you must typecast the return from GetComponent otherwise it will be a Component class instance, not an instance of GUITexture
you can either do that by properly typing crossTexture on its declaration (var crossTexture : GUITexture) or by adding as GUITexture to the GetComponent line
also, I’ve no idea why you have .MonoBehaviour there, but its definitely completely wrong.
MonoBehaviour is a class, but .enabled is an instance variable.
The code as it is in the else part is what you want and the only thing you need