Currently, I'm creating an RPG style game where the player has to click on certain "glowing" objects in order to obtain items that will be added to thier inventory in order to proceed to the next level. I've created the GUI inventory bar already and I can place items into the boxes, but I cannot figure out how I can import a GUI item on click to the inventory. If anyone could give me some ideas or possible resources that I could look at to figure something out, that would be amazing. Thank you.
答案 0 :(得分:1)
嗯,我觉得你的问题很广泛,很多都取决于其他的想法,但是让我在这里提出一些提示,希望他们中的一些能帮助你:
如果这没有回答您想要的所有内容,请更具体或在此处添加一些示例代码
修改强>
我仍然认为你的问题太宽了,你应该更多地指出它,但让我们第二次尝试:
让我们假设发光对象将这些图像作为Sprites,并在运行时将它们添加到编辑器或其他脚本中。此外,发光对象应该引用bag对象,如果可能的话,再次在运行时或编辑器中获取它。然后将其放在手套对象组件中的click方法上,这应该可以解决问题:
public void OnClickOnGlowItem() {
foreach(Sprite sprite in this.attachedItems)
this.bagObjectInterface.AddNewItem(sprite);
}