-2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyAI : MonoBehaviour
{
    //Distance entre le joueur et le zombie
    private float Distance;

    // cible du zombie
    public Transform Target;

    //distance de poursuite
    public float chaseRange = 10;

    //portée des attaques
    public float attackRange = 2.2f;

    //Cooldown des attaques
    public float attackRepeatTime = 1;
    private float attackTime;

    //Dégats infligés
    public float TheDammage;

    //Agent de navigation
    private UnityEngine.AI.NavMeshAgent agent;

    //Animation du zombie
    private Animator animation;

    void Start()
    {
        agent = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
        animation = gameObject.GetComponent<Animator>();
        attackTime = Time.time;
    }

    void Update()
    {
        //on cherche le joueur en permanence
        Target = GameObject.Find("Player").transform;

        //Calcul de la distance zombie player pour effectuée diverse action
        Distance = Vector3.Distance(Target.position, transform.position);

        //Quand player loin = idle
        if (Distance > chaseRange)
        {
            idle();
        }
        //Quand zombien'est pas asser proche pour attaquer
        if (Distance < chaseRange && Distance > attackRange)
        {
            chase();
        }
        //Quand zombie peut attaquer
        if (Distance < attackRange)
        {
            Attack();
        }

        //poursuite
        void chase()
        {
            animation.Play("walk");
            agent.destination = Target.position;
        }
        //combat
        void Attack()
        {
            // empêche le zombie de traverser le player
            agent.destination = transform.position;
            //si pas de cooldown
            if (Time.time > attackTime)
            {
                animation.Play("Hit");
                Target.GetComponent<PlayerInventory> ().ApplyDamage(TheDammage);
                Debug.Log("Le zombie a frappé" + TheDammage + "point de   dégats");
                attackTime = Time.time + attackRepeatTime;
            }
         }

        //idle
        void idle()
        {
            animation.Play("idle");
        }
    }
}

I have errors on the unit about my code but I have no error on visual studio

Asset/enemyAI.cs(67,9):error CS1547:Keyword 'void' cannot be used in this context

Asset/enemyAI.cs(67,18):error CS1525: Unexpected symbole '(',expecting ',','';' or'='

Asset/enemyAI.cs(93,0):error CS1525: Unexpected symbole '}'

I did not try anything because I really did not understand.

Nikola G.
  • 335
  • 1
  • 3
  • 9
Salers
  • 11
  • 5
  • 1
    From what I see, you are declaring a method inside a method... which is wrong. – Nikola G. May 18 '19 at 12:52
  • can you be more precise please because I am beginner. Which method do you speak? – Salers May 18 '19 at 15:16
  • Your declaring in your Update 3 new methods, void chase(), void Attack() and void idle(). If you want you could go that way... explore solution at this [OP](https://stackoverflow.com/questions/8135050/method-within-a-method). OR you could call them like... chase(), Attack() and idle(). In this case, you'll need to have them declared outside of the Update. – Nikola G. May 18 '19 at 16:13

1 Answers1

1

You aren't closing your Update function before beginning your chase function. Add another "}" after the end of your Update function to properly end that function before declaring new ones, like so:

        ...
        //Quand zombie peut attaquer
        if (Distance < attackRange)
        {
            Attack();
        }
    }   //This properly ends your Update function
        //Now we can declare the next function

    //poursuite
    void chase()
        ...

In general, if you properly maintain indentation in your files, these sorts of issues should be more obvious at a glance.

ARutherford
  • 116
  • 4