所以我正在为大学做这个小游戏,我遇到了调整精灵大小的问题。我的游戏就像一场图形冒险(猴子岛、冷酷的凡丹戈和其他东西),它有一个可以保存物品的库存。问题是,虽然世界对象精灵很好并且大小不同,但我希望它们的精灵在何时调整大小并将它们保存在库存中以便它们适合。
我认为这是使用Bounds类完成的,但我有一些问题。另外:我正在关注的教程做了一些可能会起作用的事情,但现在它给了我一个编译错误。在下面显示我保存项目的函数(并在此过程中调整其精灵的大小):
void SaveInventoryItem()
{
string name = transform.parent.gameObject.name;
GameObject temporaryObject = Instantiate(inventoryItemPrefab);
temporaryObject.name = name;
temporaryObject.gameObject.GetComponent<SpriteRenderer>().sprite = transform.parent.GetComponent<SpriteRenderer>().sprite;
temporaryObject.transform.parent = inventoryCanvas.transform;
temporaryObject.transform.position = Vector3.forward * -1;
temporaryObject.gameObject.GetComponentInChildren<InteractZone>().interactText = "Usar " + name;
Bounds bounds = temporaryObject.gameObject.GetComponent<SpriteRenderer>().sprite.bounds.size ;
float factor = General.inventoryItemSize / bounds.size.y;
}
错误说 无法从 UnityEngine.Vector3 转换为 UnityEngine.Bounds
如果有人知道解决此错误的方法或以默认大小调整精灵大小的另一种方法,请告诉我。
