- Home /
OnTriggerEnter Problem
Hi Guys im sorry to bother you with my question, but I haven´t found a solution yet. I´m currently working on a Mobspawn Skript with Java
#pragma strict
var Spawn = false;
function Update ()
{
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
Spawn = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
Spawn = false;
}
}
}
So my idea was to create an empty object wich Spawns Enemys as long as the Players collision box collides with the empty´s collison box until a certain number of mobs is reached.
I´ve checked it a hundred times by now and compared it to similiar scripts which work. But still im getting the following Errors:

Assets/Enemyspawn.js(10,10): BCE0044: expecting (, found 'OnTriggerEnter'. Assets/Enemyspawn.js(10,26): BCE0043: unexpected token: theCollider. Assets/Enemyspawn.js(10,49): UCE0001: ';' expected. insert a semicolon at the end. Assets/Enemyspawn.js(12,17): BCE0043: unexpected token: if. Assets/Enemyspawn.js(12,49): UCE0001: ';' expected. insert a semicolon at the end. Assets/Enemyspawn.js(10,10): BCE0044: expecting :, found '='.
Answer by Visual Programmer · Sep 26, 2013 at 12:24 PM
When you're checking the tag of the hit:Collider you need to reference to the gameObject first. Right now, you're asking for the tag property of the Collider.
theCollider.gameObject.tag == "Player"
That should give you what you need.
Answer by meat5000 · Sep 26, 2013 at 01:00 PM
function Update ()
{
function
There's you problem. Put your trigger functions outside Update().
Your answer
Follow this Question
Related Questions
Why am I getting a "NullReferenceException" for a Instantiate line? 1 Answer
How do you Place/Spawn a GameObject or Prefab in front of Player 2 Answers
Door Opens Automatically, then it stays open forever. How? 2 Answers
Instantiating Particle System and Editing Base Settings 0 Answers
I cant get my animation to trigger. 0 Answers