CangJie/Assets/Scripts//ItemController.cs
lspdC aed35a5f95 4.2(未合并)
1、调整老虎动画,可以在简单的逻辑下连贯播放
2、修正开局没有武器会报错的bug,第一关倒下的树的树叶可以遮挡玩家。
2022-04-03 01:36:12 +08:00

90 lines
2.1 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()
{
if(itemList[displayIndex]!=null)
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() {
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();
}
}