116 lines
2.0 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-11-30
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "Cha_Damage" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace G
{
/// <summary>
/// 角色伤害
/// </summary>
public class Cha_Damage : MonoBehaviour
{
#region Field
public bool impactDestroy;
public float destroytime;
public float colliderofftime;
private float _currentTime;
private Transform _transform;
private Collider _collider;
#endregion
#region Property
public int damage
{
get;
set;
}
#endregion
#region Method
public void PressDamage(int a)
{
damage = a;
}
#endregion
#region Unity
private void Awake()
{
_transform = this.transform;
_collider = this.GetComponent<Collider>();
}
private void OnEnable()
{
_currentTime = 0f;
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == GameLayer.AllyLayer)
{
Vector3 forward = _transform.forward;
forward.y = damage;
other.transform.root.SendMessage("Damaged", forward);
if (impactDestroy)
{
this.gameObject.SetActive(false);
_transform.position = Vector3.one * 5f;
}
}
}
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;
}
}
}
// Use this for initialization
private void Start()
{
}
#endregion
}
}