The full warning message:
You are trying to create a
MonoBehaviourusing thenewkeyword. This is not allowed.MonoBehaviourscan only be added usingAddComponent(). Alternatively, your script can inherit fromScriptableObjector no base class at all
And in both scripts I'm not using the new keyword:
The DetectPlayer script:
public class DetectPlayer : MonoBehaviour
{
private int counter = 0;
private void OnGUI()
{
GUI.Box(new Rect(300, 300, 200, 20),
"Times lift moved up and down " + counter);
}
}
The Lift script:
public class Lift : MonoBehaviour
{
private bool pressedButton = false;
private DetectPlayer dp = new DetectPlayer();
private void OnGUI()
{
if (pressedButton)
GUI.Box(new Rect(300, 300, 200, 20), "Press to use lift!");
}
}