| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.U2D;
- public class BeHitTrigger : MonoBehaviour
- {
- public Character owner;
- public int attackerID; //攻击方
- [Header("当前X值(攻击值-抗击打值)")]
- [DisplayOnly]
- public int curX;
- //闪白参数
- private bool isWhite;
- private float white;
- public List<Material> mats;
- private void Awake()
- {
- owner = GetComponentInParent<Character>();
- mats = new List<Material>();
- }
- private void CountTurnWhiteMaterials()
- {
- foreach (Material m in owner.meshRenderer.materials)
- {
- if (m.shader.name.Contains("Fill"))
- {
- mats.Add(m);
- }
- }
- }
- public void BeHit(int damage)
- {
- owner.BeHit(damage);
- }
- public void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom)
- {
- owner.BeHit(attackMethod,attackFrom);
- //Debug.Log(attackInfo.damage + "" + attackFrom.name);
- }
- public void JudgeTurnWhite(bool isDemSummon, Character owner)
- {
- //敌方士兵受到起手式伤害/我方士兵受到伤害
- if (isDemSummon || owner.GetComponent<Demonic>())
- {
- TurnWhite();
- }
- }
- private void TurnWhite()
- {
- if (mats.Count == 0)
- {
- CountTurnWhiteMaterials();
- }
- foreach(Material m in mats)
- {
- m.SetFloat("_FillPhase", 0.6f);
- Invoke("TurnOrigColor", 0.1f);
- }
- }
- private void OnEnable()
- {
- isWhite = false;
- mats = new List<Material>();
- }
- private void OnDisable()
- {
- foreach (Material m in mats)
- {
- m.SetFloat("_FillPhase", 0);
- }
- }
- private void TurnOrigColor()
- {
- isWhite = true;
- white = 0.6f;
- }
- private void Update()
- {
- if (isWhite)
- {
- white -= 4f * Time.deltaTime;
- foreach(Material m in mats)
- {
- m.SetFloat("_FillPhase", white);
- }
- if (white <= 0)
- {
- isWhite = false;
- }
- }
- }
- }
|