我如何在预定式的gameObject中称呼另一个gameObject的可能性?

发布于 2025-02-12 19:41:31 字数 168 浏览 1 评论 0原文

如果是不可能的,我至少可以使用射线跟踪找到它吗?

我想制作一些敌人的游戏对象(这些游戏是从预制的,随机产卵的实例化)总是看着玩家。

我认为我不能称其为XYZ坐标,但也许我可以使用射线缩放找到它们?我该怎么做?即使我知道什么是射线跟踪,并且在其他非统一项目中使用了它,我也不知道如何团结地实施它。

If that is not possible, can I at least find it using raytracing?

I want to make some enemy GameObjects (which are instantiated from a prefab, which spawn randomly) always look towards the player.

I don't think I can just call it's xyz coordinates, but maybe I can find them using raytracing? How exactly do I do that? Even if I know what raytracing is and used it before in other non-unity projects, I have no idea how to implement it in unity.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2025-02-19 19:41:31

您的敌人应该能够以某种方式获得参考(可能是入门级的单例,或者是专业人士的依赖注入)并使用player.Transform.Posit.position。

基本上您的玩家应该看起来像这样:

public class Player : MonoBehaviour 
{
    public static Player Instance;

    void Awake()
    {
        Instance = this;
    }
}

然后敌人可以使用:

Player.Instance.transform.position

使玩家位置保持位置。

Your enemies should be able to get reference to player somehow (probably Singleton for entry level, or Dependency Injection for pros) and use player.transform.position

So basically your player should look like that:

public class Player : MonoBehaviour 
{
    public static Player Instance;

    void Awake()
    {
        Instance = this;
    }
}

And then enemy can use:

Player.Instance.transform.position

to get players position.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文