weixin_63967673 2022-08-31 16:34 采纳率: 94.1%
浏览 34
已结题

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<Animator>();
        agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
        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;
        }
    }
}

  • 写回答

2条回答 默认 最新

  • 陈言必行 Unity领域优质创作者 2022-08-31 20:54
    关注

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

    Transform Wol;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月9日
  • 已采纳回答 9月1日
  • 创建了问题 8月31日

悬赏问题

  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)