CangJie/Assets/Scripts//ItemController.cs
lspdC dbb026271f 1、初步完成武器栏 树木交互
2、尝试用对象池实现手持武器切换(还未完成)
3、在一些简单的继承问题上对京力的部分代码进行修改(集中在Interactable类中)
2022-03-15 20:26:46 +08:00

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();
}
}