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