VR:将项目从列表中放入

发布于 2025-02-11 08:54:32 字数 617 浏览 0 评论 0原文

我希望你一切都好。

因此,我正在创建一个带有XR游戏的VR,其中我将项目列表作为脚本化对象。现在,当我按下按钮时,我想将一项放在手中,但是我会遇到问题,因为我的功能没有做正确的事情。它的外观就是这样:

public void PutItemInHand()
{
    for (int i = 0; i < inventoryItems.Count; i++)
    {
        if (inventoryItems[i].name == "Sword")
        {
            Instantiate(inventoryItems[i], handSpawn.position, handSpawn.rotation);
        }
        else if (inventoryItems[i].name == "Gun")
        {
            Instantiate(inventoryItems[i], handSpawn.position, handSpawn.rotation);
        }
    }
}

也说:“无法实例化具有位置和旋转的ScriptableObject”。

你们有一个主意吗?我将感谢任何帮助。 亲切的问候

I hope you are doing well.

So I am creating a VR with XR game in which I have a list of items as Scriptable Objects. Now I want to put one item in my hand when I press a button but I run into problems because my function is not doing the right thing. This is how it looks like:

public void PutItemInHand()
{
    for (int i = 0; i < inventoryItems.Count; i++)
    {
        if (inventoryItems[i].name == "Sword")
        {
            Instantiate(inventoryItems[i], handSpawn.position, handSpawn.rotation);
        }
        else if (inventoryItems[i].name == "Gun")
        {
            Instantiate(inventoryItems[i], handSpawn.position, handSpawn.rotation);
        }
    }
}

Also it says: "Cannot instantiate a ScriptableObject with a position and rotation".

Do you guys have an idea? I would be grateful for any help.
Kind regards

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

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

发布评论

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

评论(1

我爱人 2025-02-18 08:54:32

没错,您不能仅仅因为ScriptableObjects没有组件或转换,就无法实例化具有位置或旋转的脚本对象。

您想做的是实例化项目的预制,因此您可以执行实例化(contectoryItems [i] .itemprefab,handspawn.position.position,handspawn.rotation);>> >

It is right, you can not instantiate a scriptable object with a position or rotation, simply because ScriptableObjects don't have components nor Transforms.

what you want to do is instantiate a prefab of your item, so you can do something like Instantiate(inventoryItems[i].itemPrefab, handSpawn.position, handSpawn.rotation);

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