Capitalization errors. For example “Timer” and “timer” are not the same thing. You need to make sure capitalization matches
All of your functions after OnCollisionEnter2D are actually INSIDE OnCollisionEnter2D. You do not want this.Move those functions outside of OnCollisionEnter2D. Check where your { and } brackets are. Notice the indentation of all those functions. That’s a hint they’re in the wrong place.
Fix those things, then come back if you need more help.
I’ll add some comments to a snippet of your code to explain the issue more clearly:
void OnTriggerEnter2D(Collider2D trig)
// This '{' marks the START of the OnTriggerEnter2D function. When we see a matching '}' that will mark the end of the function
{
if (trig.gameObject.tag == "Player")
// This marks the START of the if statement
{
target = trig.gameObject;
inRange = true;
// This marks the END of the if statement
}
// Normally I would expect now to see a '}' to end the OnCollider2D function..
// Instead we see the beginning of the EnemyLogic function here! That means we are still inside OnCollision2D but we are now seeing the start of a new function. This is bad!
void EnemyLogic()
{
Ok, thanks for the explanation but how do I fix it?
Does this work?
void OnTriggerEnter2D(Collider2D trig)
{
if (trig.gameObject.tag == “Player”)
{
target = trig.gameObject;
inRange = true;
}
}
void EnemyLogic()
{
yep, that looks right, assuming the rest of the brackets in your code match up after that part. That may not fix all of your errors but you’re getting closer.
I fix some error now because I miss spell most of the stuff
Now I only have 2 error
On line 135,13 and 139,13
‘Debug’ is an ambiguous reference between ‘UnityEngine.Debug and ‘System.Diagnostics.Debug’