
随机物品(U7 LWRP)
从书中随机生成一个物品!让命运决定你的玩法!观看视频,看看它的实际效果。
查看大图public class ItemRandomItem : MonoBehaviour { protected Item item; int numberOfItems; int randomNumber; string itemName; ItemData spawnedItemData; 物品 生成物品; 变换 持有者点; protected void Awake() { item = this.GetComponent(); item.transform.Find("Mesh").gameObject.SetActive(false); numberOfItems = Catalog.current.GetDataList(Catalog.Category.Item).Count; Debug.Log("你的游戏中有 " + numberOfItems + " 个物品"); do { randomNumber = Random.Range(0, numberOfItems); itemName = Catalog.current.GetDataList(Catalog.Category.Item)[randomNumber].id; Debug.Log("您正在尝试实例化的物品是 " + itemName); spawnedItemData = Catalog.current.GetData(itemName, true); } while (!spawnedItemData.purchasable || spawnedItemData.Interactables.Count == 0); spawnedItem = spawnedItemData.Spawn(true); } void Update() { spawnedItem.transform.position = item.transform.position; if (Player.local.body.GetHand(Pointer.activeSide).interactor.grabbedHandle != null) { Player.local.body.GetHand(Pointer.activeSide).interactor.UnGrab(false); Player.local.body.GetHand(Pointer.activeSide).interactor.Grab(spawnedItem.GetMainHandle(Pointer.activeSide), true); } else { holderPoint = spawnedItem.definition.holderPoint; spawnedItem.transform.rotation = holderPoint.rotation; } item.Disappear(); } }
还没有人评论,去客户端里说两句吧。
评论在新手盒子客户端中发表,这里同步展示。