I am trying to enable/disable a script from the same gameObject and it gives this error…‘enabled’ is not a member of UnityEngine.Component…I have tried searching other results and none of them work…
here is the code…EnemyAIPathfinding is the name of the script I am trying to enable/disable
function Start ()
{
this.gameObject.GetComponent("EnemyAIPathfinding").enabled = false;
}
function Update()
{
if......something something something
{
this.gameObject.GetComponent("EnemyAIPathfinding").enabled = true;
}
}
Leave out the quotes:
this.gameObject.GetComponent(EnemyAIPathfinding).enabled = true;
When you use quotation marks on the parameter, the compiler does not know the type, so the compiler returns a Component. A Component does not have an enable flag. The enable flag is introduced in the Behavior class. Behavior inherits from Component, and Monobehavior inherits from Behavior.
I know its old, but this hasnt been answered yet and it showed up as Nr. 1 on google as I searched for the same issue.
I have figured it out by now and would like to give my answer:
this.gameObject.GetComponent<EnemyAIPathfinding>().enabled = false;
It still didn’t work…it gave me the error…The name ‘EnemyAIPathfinding’ does not denote a valid type(‘not found’)…I have no idea what to do…I looked at other unity questions but none of them solve my problem.