VR:将项目从列表中放入
我希望你一切都好。
因此,我正在创建一个带有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没错,您不能仅仅因为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);