2025-05-18 01:04:31 +08:00

97 lines
1.9 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "EnemyDamage" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
using UnityEngine;
namespace G
{
/// <summary>
/// 怪物攻击
/// </summary>
public class EnemyDamage : MonoBehaviour
{
public int damage;
public bool impactDestroy;
public float destroytime;
public float colliderofftime;
private float _currentTime;
private Collider _collider;
private int _hit = 0;
private void Awake()
{
_collider = this.GetComponent<Collider>();
_currentTime = 0f;
}
private void OnEnable()
{
_currentTime = 0f;
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == GameLayer.AllyLayer)
{
Vector3 forward = transform.forward;
forward.y = damage;
if (EntityCart.Instance)
EntityCart.Instance.Damaged(forward);
else
EntityMainPlayer.Instance.Damaged(forward, _hit);
if (impactDestroy)
{
this.gameObject.SetActive(false);
transform.position = Vector3.one * 5f;
}
}
}
public void PressDamage(int a)
{
damage = a;
}
public void SetDamage(int d, int hit)
{
damage = d;
_hit = hit;
}
private void Update()
{
if (destroytime > 0f)
{
_currentTime += Time.deltaTime;
if (colliderofftime > 0f && _currentTime >= colliderofftime)
{
_collider.enabled = false;
}
if (_currentTime >= destroytime)
{
_currentTime = 0f;
this.gameObject.SetActive(false);
transform.position = Vector3.one * 5f;
_collider.enabled = true;
}
}
}
}
}