Hi, i want to make an enemy behind a corner come out and follow you when you step on a cube. I have all the scripts but this one doesn’t work i dont know why
here’s my script:
function OnControllerColliderHit(hit:ControllerColliderHit) {
var script : EnemyAI;
var script : EnemyAttack;
if(hit.gameObject.tag == "Instantiate enemy")
{
GetComponent(EnemyAI).enabled = true;
GetComponent(EnemyAttack).enabled = true;
}
}
what should i do?
the enemy has EnemyAI and EnemyAttack disabled and when you step on a cube i want them to be enabled but i get 2 errors:
Assets/Scripts/Enable script.js(4,14): BCE0018: The name ‘EnemyAI’ does not denote a valid type (‘not found’). Did you mean ‘System.Enum’?
Assets/Scripts/Enable script.js(5,14): BCE0018: The name ‘EnemyAttack’ does not denote a valid type (‘not found’).
Leave this script where it is and move your two C# scripts (EnemyAI, EnemyAttack) under a folder named: “Plugins” - create one if it does not exist yet).
Take a look at this: Unity - Scripting API:
Unity compiles scripts in a certain order. So if you are ever trying to access C# from JavaScript or the other way around, you need to make sure you have them in the proper location. Either move your C# script to a folder called Plugins or move your JavaScript files to the Standard Assets folder.
Please cache the components…
var enemyAIScript : EnemyAI;
var enemyAttackScript : EnemyAttack;
function Start()
{
enemyAIScript=gameObject.GetComponent.<EnemyAI>();
enemyAttackScript=gameObject.GetComponent.<EnemyAttack>();
}
function OnControllerColliderHit(hit:ControllerColliderHit)
{
if(hit.gameObject.tag == "Instantiate enemy")
{
enemyAIScript.enabled = true;
enemyAttackScript.enabled = true;
}
}