unity简单怪兽AI报错

报错Assets\Scenes\GuaiWu.cs(23,9): error CS0103: The name 'Wol' does not exist in the current context


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GuaiWu : MonoBehaviour
{
    public enum EnemyState
    {
        idle,
        run,
        attack,
        death,
        
    }
    public EnemyState CurrentState = EnemyState.idle;
    Animator imator;
    UnityEngine.AI.NavMeshAgent agent;
    // Start is called before the first frame update
    void Start()
    {
        imator = GetComponent();
        agent = GetComponent();
        Wol = GameObject.FindWithTag("Wolf").transform;
    }

    // Update is called once per frame
    void Update()
    {
        float distance = Vector3.Distance(Wol.position, transform.position);
        switch (CurrentState)
        {
            case EnemyState.idle:
                if (distance > 2 && distance <= 10)
                {
                    CurrentState = EnemyState.run;
                }
                if (distance < 2)
                {
                    CurrentState = EnemyState.attack;
                }
                imator.Play("Idle");
                agent.isStopped = true;
                break;
            case EnemyState.run:
                if (distance > 10)
                {
                    CurrentState = EnemyState.idle;
                }
                if (distance < 2)
                {
                    CurrentState = EnemyState.attack;
                }
                imator.Play("Run");
                agent.isStopped = false;
                agent.SetDestination(Wol.position);
                break;
        }
    }
}

在第18行后面添加个定义就可以了,代码如下:

Transform Wol;

wol没有定义直接使用了
定义一个 Transform wol;