Hey everyone, I’m programming an A.R game for mobile and when the tracking is lost I need to disable some mono behaviours. But, in some scripts the void OnEnable and OnDisable should be only called in some special ocasions, so I create an interface and in these scripts I inherit the interface which contains a property called isDisabledDueToTracking.
This way I can know if the behaviour has been disabled because the special ocasion was reached or because the tracking was lost. Until now, everything is ok, but I’m having problems to set values to this property. Here’s the code:
public interface IMonoSpecial {
bool isDisabledDueToTracking {
get;
set;
}
}
using UnityEngine;
using System.Collections.Generic;
public class gameHandler : MonoBehaviour {
/// [.......]
public void switchMonoState (bool state) {
if(!state) {
MonoBehaviour[] mono = (MonoBehaviour[])GameObject.FindObjectsOfType(typeof(MonoBehaviour));
foreach(MonoBehaviour _mono in mono) {
if(_mono != this && _mono.gameObject != ARCamera && _mono.gameObject != ImageTarget && _mono != _trackerHandler) {
_mono.enabled = state;
if(_mono is IMonoSpecial) _mono.isDisabledDueToTracking = true;
// THE PROBLEM IS IN THE LINE ABOVE LINE: Type `UnityEngine.MonoBehaviour' does not contain a definition for `IMonoSpecial' and no extension method `IMonoSpecial' of type `UnityEngine.MonoBehaviour' could be found
activedBehaviours.Add(_mono);
}
}
} else {
foreach(MonoBehaviour _mono in activedBehaviours) {
_mono.enabled = true;
}
activedBehaviours = new List<MonoBehaviour>();
}
}
// [.............]
}
Anyone can help me with this? I’m not sure about what I’m missing in the code. Interfaces are not my strong. heheh
Thanks from now!!!