unity3d Unity 3D:错误CS0116:命名空间不能直接包含字段或方法等成员

ruarlubt  于 2022-12-13  发布在  其他
关注(0)|答案(1)|浏览(365)

我在Unity中为敌人编写AI代码,但是Unity给了我这个错误。它说错误在第21行,但是我找不到它。任何帮助都是感激的!

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

public class EnemyController : MonoBehaviour
{
    public float lookRadius = 10f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
    void OnDrawGizmosSelected()
{
    Gizmos.color = Color.red;
    Gizmos.DrawWireSphere(transform.position, lookRadius);
}
vuktfyat

vuktfyat1#

在空的Update()函数后面有一个不属于这里的右括号,它应该在OnDrawGizmosSelected()下面,这样它就可以包含EnemyController类,如下所示:

public class EnemyController : MonoBehaviour
{
    public float lookRadius = 10f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, lookRadius);
    }
}

相关问题