[PLEASE HELP] I'm trying to do a enemy behavior script and I'm very new to Unity

There are 8 errors

  1. ‘Timer is a type, which is not valid in the given context
  2. ‘RaycastDebugger’ does not exist in the current context
  3. ‘EnemyLogic’ does not exist in the current context
  4. ‘StopAttack’ does not exist in the current context
  5. ‘targetPosition’ does not exist in the current context
  6. ‘Timeout’ does not contain a definition for ‘deltaTime’
  7. ‘Timer’ is a type but is used like a variable
  8. ‘Debug’ is an ambiguous reference between ‘UnityEngine.Debug and ‘System.Diagnostics.Debug’

----------------------------------------------------------- Here is the script ------------------------------------------
EnemyBehaviour Script - Pastebin.com for pastebin
https://hastebin.com/ajejisonuj.cs for hastebin

The gist of your errors are two major problems:

  • 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.

1 Like

How do I move functions out of OnCollisionEnter2D? and ty :slight_smile:
OMG I got a trophy :smile:

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 :eyes:
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’

From the top of your file delete this line:

using System.Diagnostics;
1 Like

OMG yes it work!!!
thanks for everything :smile: