You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
63 lines
2.0 KiB
3 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
//盾牌,可以抵挡一次敌人的攻击,会消耗一次层数
|
||
|
//普通的敌人会停在原地,并准备下一次攻击(有一定的硬直时间)
|
||
|
public class LightShield : MonoBehaviour {
|
||
|
//最大层数
|
||
|
public int maxLayer_;
|
||
|
//当前层数
|
||
|
public int remainLayer_;
|
||
|
//层级对应盾牌对象
|
||
|
public GameObject[] LayerObjs_;
|
||
|
//获取玩家控制类
|
||
|
private PlayerControl playerControl_;
|
||
|
public Image shieldRecoverImg;
|
||
|
public bool isRecovering;
|
||
|
public ParticleSystem breakEffect;
|
||
|
|
||
|
|
||
|
//持盾状态下盾牌被攻击
|
||
|
public void shieldHit() {
|
||
|
if (remainLayer_ > 1) {
|
||
|
remainLayer_ -= 1;
|
||
|
LayerObjs_[remainLayer_].SetActive(false);
|
||
|
}
|
||
|
else {
|
||
|
remainLayer_ -= 1;
|
||
|
LayerObjs_[remainLayer_].SetActive(false);
|
||
|
gameObject.GetComponent<BoxCollider>().enabled = false;
|
||
|
breakEffect.Play();
|
||
|
}
|
||
|
}
|
||
|
void Start()
|
||
|
{
|
||
|
playerControl_ = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControl>();
|
||
|
isRecovering = false;
|
||
|
}
|
||
|
//玩家在盾牌受到损伤后,会渐渐恢复
|
||
|
void Update()
|
||
|
{
|
||
|
if (remainLayer_ < maxLayer_ && !isRecovering) {
|
||
|
isRecovering = true;
|
||
|
playerControl_.startRecoverShield();
|
||
|
}
|
||
|
shieldRecoverImg.fillAmount = playerControl_.shieldRecover / 30f;
|
||
|
if (playerControl_.shieldRecover == 30) {
|
||
|
LayerObjs_[remainLayer_].SetActive(true);
|
||
|
remainLayer_ += 1;
|
||
|
if (!gameObject.GetComponent<BoxCollider>().enabled) {
|
||
|
gameObject.GetComponent<BoxCollider>().enabled = true;
|
||
|
}
|
||
|
playerControl_.shieldRecover = 0;
|
||
|
shieldRecoverImg.fillAmount = 0;
|
||
|
playerControl_.stopRecoverShield();
|
||
|
isRecovering = false;
|
||
|
breakEffect.Play();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|