CangJie/Assets/Scripts//ItemController.cs
Roman 7db9125c45 Squashed commit of the following:
commit dbb026271fc709d07b36b271b11997919d15f3e0
Author: lspdC <961907320@qq.com>
Date:   Tue Mar 15 20:26:46 2022 +0800

    1、初步完成武器栏 树木交互
    2、尝试用对象池实现手持武器切换(还未完成)
    3、在一些简单的继承问题上对京力的部分代码进行修改(集中在Interactable类中)

commit c5cbe5ba76fcf20db855016ebfa33bb9ef79f390
Author: lspdC <961907320@qq.com>
Date:   Tue Mar 15 10:39:58 2022 +0800

    合并3.14分支

commit f3b7fd6631a3c3b87b17ac40b4542c2485103b46
Author: lspdC <961907320@qq.com>
Date:   Tue Mar 15 10:37:34 2022 +0800

    3.14进度(合并前)

# Conflicts:
#	UserSettings/EditorUserSettings.asset
2022-03-19 17:47:36 +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();
}
}