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.
109 lines
2.8 KiB
109 lines
2.8 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.Events; |
|
using UnityEngine.Serialization; |
|
|
|
public class HitCheck : MonoBehaviour |
|
{ |
|
public Collider col; |
|
public void Initialized(object data, int layer, int cntPenetrate, System.Action OnUseMax) |
|
{ |
|
if (col == null) |
|
col = GetComponent<Collider>(); |
|
|
|
owner = (Character)data; |
|
gameObject.layer = layer; |
|
this.OnUseMax = OnUseMax; |
|
|
|
Activetion(true, cntPenetrate); |
|
|
|
gameObject.SetActive(true); |
|
} |
|
|
|
[Space(10)] |
|
public Character owner; |
|
public int cntPenetrate; |
|
public void Activetion(bool ON, int cntPenetrate = 0) |
|
{ |
|
this.cntPenetrate = cntPenetrate; |
|
|
|
if (col == null) |
|
col = GetComponent<Collider>(); |
|
col.enabled = ON; |
|
} |
|
public void Activetion(int cntPenetrate) |
|
{ |
|
this.cntPenetrate = cntPenetrate; |
|
|
|
if (col == null) |
|
col = GetComponent<Collider>(); |
|
col.enabled = true; |
|
} |
|
public void Activetion_Collider(bool ON) |
|
{ |
|
col.enabled = ON; |
|
} |
|
public void Activetion_Penetrate(int cnt) |
|
{ |
|
cntPenetrate = cnt; |
|
gameObject.SetActive(true); |
|
} |
|
private void OnDisable() |
|
{ |
|
if (col == null) |
|
col = GetComponent<Collider>(); |
|
col.enabled = false; |
|
} |
|
|
|
System.Action OnUseMax; |
|
[Space(10)] |
|
public bool DAMAGE = true; |
|
public DamageType damageType = DamageType.None; |
|
public float damageValue = 0; |
|
public float knockBackAddRate = 1f; |
|
[Space(10)] |
|
public bool RADAR = false; |
|
private void OnTriggerEnter(Collider other) |
|
{ |
|
if (other.CompareTag("HitCheckException") || other.CompareTag("DropItem")) |
|
return; |
|
//if (other.name.Equals("Floor")) |
|
// return; |
|
if (RADAR && (other.CompareTag("Radar") || other.CompareTag("Bomb"))) |
|
return; |
|
|
|
if (0 < cntPenetrate--) |
|
{ |
|
if (DAMAGE && other.CompareTag("HitBox")) |
|
other.gameObject.SendMessage("Hit", this);//맞은 놈 |
|
|
|
OnHited(); |
|
|
|
if (cntPenetrate == 0) |
|
{ |
|
if (OnUseMax != null) |
|
OnUseMax(); |
|
} |
|
} |
|
} |
|
|
|
[Space(10)] |
|
public GameObject prefabEffHit; |
|
[System.Serializable] |
|
public class HitEvent : UnityEvent<bool> { } |
|
[FormerlySerializedAs("onHited")] |
|
[SerializeField] |
|
[Space(10)] |
|
private HitEvent onHited = new HitEvent(); |
|
void OnHited() |
|
{ |
|
if (prefabEffHit != null) |
|
{ |
|
Transform eff = owner.map.ObjectCreate(prefabEffHit, null, Vector3.one, transform.position).transform; |
|
eff.eulerAngles = transform.eulerAngles; |
|
} |
|
|
|
onHited.Invoke(true); |
|
} |
|
}
|
|
|