using System.Collections; using System.Collections.Generic; using UnityEngine; public class ItemController : UnitySingleton { int displayIndex=0; Item displayItem; public List itemList = new List(); Player player; void Start() { player = FindObjectOfType(); Display(); } // Update is called once per frame void Update() { } //添加物品 public void AddItem(Item item) { itemList.Add(item); } /// /// 用于Player获取物品 /// public Item GetItem() { return itemList[displayIndex]; } /// /// 用于强制改变Player的物品 /// public void SetItem() { player.weapon = itemList[displayIndex]; } /// /// 展示正在使用的物品 /// public void Display() { SetItem(); displayItem = Instantiate(itemList[displayIndex],Vector3.zero,Quaternion.identity,transform); displayItem.transform.localPosition = Vector3.zero; } public void LeftChangeItem() { player.WeaponReturn(); Destroy(displayItem.gameObject); displayIndex = (displayIndex - 1 + itemList.Count)%itemList.Count; Display(); player.WeaponInPosition(); } public void RightChangeItem() { player.WeaponReturn(); Destroy(displayItem.gameObject); displayIndex = (displayIndex + 1)%itemList.Count; Display(); player.WeaponInPosition(); } public void ToLastestItem() { player.WeaponReturn(); Destroy(displayItem.gameObject); displayIndex = itemList.Count-1; Display(); player.WeaponInPosition(); } public void ReplaceItem(Item newItem) { player.WeaponReturn(); Destroy(displayItem.gameObject); itemList[displayIndex] = newItem; Display(); player.WeaponInPosition(); } }