简体   繁体   English

看敌方半径统一3D

[英]Look Radius of Enemy unity 3D

In my code I am trying to establish and a look radius on how far the AI enemy can see the player.在我的代码中,我试图建立并查看 AI 敌人可以看到玩家多远的半径。 When I run the code It comes up with "gizmo drawing functions can only be used in ondrawgizmos and ondrawgizmosselected".当我运行代码时,它会出现“gizmo 绘图功能只能在 ondrawgizmos 和 ondrawgizmosselected 中使用”。 I don't know what this means or what I should do.我不知道这意味着什么或我应该做什么。 Please help, thank you.请帮忙,谢谢。

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

public class EnemyFollow : MonoBehaviour
{

    public float lookRadius = 10;
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

My C# code我的 C# 代码

I think you should do kinda next thing:我认为你应该做接下来的事情:

public float lookRadius = 10;

void OnDrawGizmos(){
    Gizmos.DrawSphere(transform.position, lookRadius);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM