Error on my javascript code

Hey guys, can you please tell me why i am getting an error?

var moveSpeed = 5.0;
var Enemy = false;
   

function OnTriggerEnter(collision : Collider){
	if(collision.gameObject.tag == ("Player")){
	     InvokeRepeating("Enemy", 0.01, 3);
	     Enemy = true;
     }
}

function Enemy(){
	gameObject.Find("Player").SendMessage("Damage");
}        
             
                       
function Update (){
    transform.position.x -= moveSpeed * Time.deltaTime;

}

And i get this Error; ((((Assets/EnemyMovesLeft.js(12,10): BCE0089: Type ‘EnemyMovesLeft’ already has a definition for ‘Enemy’.))))

does anyone know what im doing wrong?

variable names MUST BE LOWER CASE also never ever re-use words. so CHANGE your variable name to something totally different like "blue" or "potato" or "elephant" - any other word.

1 Answer

1

Hey dave guess who’s back :slight_smile:

Your problem probably comes from the fact that you have a var called Enemy and a function called the same. Try to rename one of them.

owww, crap. but i thought i was creating a variable and using it as a function? my javascript abilities are very very small. i only touched my first code a few months ago and crashed coursed myself into learning

using a variable as a function? no that doesn't exist. If your question is answered please accept an answer.

you guys are legends, thankyou