优化敌人碰到死亡时的表现效果
This commit is contained in:
@@ -86,6 +86,11 @@ namespace IndianOceanAssets.Engine2_5D
|
||||
HealthSystem health = other.GetComponent<HealthSystem>();
|
||||
if (health != null)
|
||||
{
|
||||
// 激活怪物身上的灵灯光照(3秒亮起效果)
|
||||
var lanternLight = other.GetComponent<EnemyLanternLight>();
|
||||
if (lanternLight != null)
|
||||
lanternLight.ActivateLight();
|
||||
|
||||
// 在伤害前记录信息(用于掉落,因为 Die() 会 Destroy gameObject)
|
||||
Vector3 deathPos = other.transform.position;
|
||||
int enemyMaxHp = health.MaxHealth;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IndianOceanAssets.Engine2_5D
|
||||
{
|
||||
/// <summary>
|
||||
/// 怪物灵灯光照响应 —— 挂到敌人预制体上。
|
||||
/// 当怪物被灵灯碰触时,在敌人位置创建一个独立光源,亮起 3 秒后消失。
|
||||
/// 光源独立于敌人存在,即使敌人立即死亡也能正常显示。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(HealthSystem))]
|
||||
public class EnemyLanternLight : MonoBehaviour
|
||||
{
|
||||
[Header("光照参数")]
|
||||
[Tooltip("亮起持续时间(秒)")]
|
||||
[SerializeField] private float lightDuration = 3f;
|
||||
|
||||
[Tooltip("亮起时的光照半径")]
|
||||
[SerializeField] private float lightRadius = 3f;
|
||||
|
||||
[Tooltip("亮起时的光照强度")]
|
||||
[SerializeField] private float lightIntensity = 0.8f;
|
||||
|
||||
/// <summary>
|
||||
/// 由 SpiritLantern 在碰触时调用。
|
||||
/// 在敌人当前位置创建一个独立光源,3秒后自动销毁。
|
||||
/// </summary>
|
||||
public void ActivateLight()
|
||||
{
|
||||
// 在敌人位置创建独立光源物体
|
||||
GameObject lightObj = new GameObject("EnemyLanternGlow");
|
||||
lightObj.transform.position = transform.position;
|
||||
|
||||
// 添加 LightSource 组件
|
||||
LightSource ls = lightObj.AddComponent<LightSource>();
|
||||
ls.SetRadius(lightRadius);
|
||||
ls.SetIntensity(lightIntensity);
|
||||
|
||||
// 启动自动销毁协程(挂在独立物体上,不受敌人死亡影响)
|
||||
lightObj.AddComponent<AutoDestroyLight>().Initialize(ls, lightDuration);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部辅助组件:光源亮起后渐隐并自动销毁。
|
||||
/// </summary>
|
||||
internal class AutoDestroyLight : MonoBehaviour
|
||||
{
|
||||
private LightSource _lightSource;
|
||||
private float _duration;
|
||||
private float _elapsed;
|
||||
|
||||
public void Initialize(LightSource ls, float duration)
|
||||
{
|
||||
_lightSource = ls;
|
||||
_duration = duration;
|
||||
_elapsed = 0f;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_elapsed += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(_elapsed / _duration);
|
||||
|
||||
if (_lightSource != null)
|
||||
{
|
||||
// 前 70% 保持全亮,后 30% 渐隐
|
||||
float fadeT = Mathf.Clamp01((t - 0.7f) / 0.3f);
|
||||
_lightSource.SetIntensity(Mathf.Lerp(0.8f, 0f, fadeT));
|
||||
}
|
||||
|
||||
if (t >= 1f)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: D3hO5yP7UCipShm8W1Pt2Wgs5oJxdh3wKR8An3CkL8wif3zwawZE19o=
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -316,6 +316,8 @@ GameObject:
|
||||
- component: {fileID: 350980459442417952}
|
||||
- component: {fileID: 1893771889199554109}
|
||||
- component: {fileID: -534909058101112079}
|
||||
- component: {fileID: 4886022223885430410}
|
||||
- component: {fileID: 8846277074571078222}
|
||||
m_Layer: 6
|
||||
m_HasEditorInfo: 1
|
||||
m_Name: Enemy1
|
||||
@@ -478,7 +480,7 @@ MonoBehaviour:
|
||||
maxHealth: 3
|
||||
deathEffect: {fileID: 0}
|
||||
isPlayer: 0
|
||||
dissolveMaterial: {fileID: 0}
|
||||
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
|
||||
fadeDuration: 2
|
||||
--- !u!114 &1893771889199554109
|
||||
MonoBehaviour:
|
||||
@@ -516,6 +518,41 @@ MonoBehaviour:
|
||||
disableOutline: 0
|
||||
outlineColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
outlineWidth: 5
|
||||
--- !u!114 &4886022223885430410
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 02ab9f3c1d1d97248b596a5863684b6c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
lightDuration: 3
|
||||
lightRadius: 3
|
||||
lightIntensity: 0.8
|
||||
--- !u!114 &8846277074571078222
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2657273ac9b36264fb8d255879c18f77, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
radius: 2
|
||||
intensity: 0
|
||||
registerOnStart: 0
|
||||
offset: {x: 0, y: 0, z: 0}
|
||||
followTarget: {fileID: 0}
|
||||
enableFlicker: 0
|
||||
flickerSpeed: 5
|
||||
flickerAmount: 0.2
|
||||
--- !u!1 &8348150211127470280
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -228,6 +228,8 @@ GameObject:
|
||||
- component: {fileID: 350980459442417952}
|
||||
- component: {fileID: 1893771889199554109}
|
||||
- component: {fileID: 1378211221191342921}
|
||||
- component: {fileID: -2178740973264773340}
|
||||
- component: {fileID: 954861008086257599}
|
||||
m_Layer: 6
|
||||
m_HasEditorInfo: 1
|
||||
m_Name: Enemy2
|
||||
@@ -390,7 +392,7 @@ MonoBehaviour:
|
||||
maxHealth: 3
|
||||
deathEffect: {fileID: 0}
|
||||
isPlayer: 0
|
||||
dissolveMaterial: {fileID: 0}
|
||||
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
|
||||
fadeDuration: 2
|
||||
--- !u!114 &1893771889199554109
|
||||
MonoBehaviour:
|
||||
@@ -428,6 +430,41 @@ MonoBehaviour:
|
||||
disableOutline: 0
|
||||
outlineColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
outlineWidth: 5
|
||||
--- !u!114 &-2178740973264773340
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 02ab9f3c1d1d97248b596a5863684b6c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
lightDuration: 3
|
||||
lightRadius: 3
|
||||
lightIntensity: 0.8
|
||||
--- !u!114 &954861008086257599
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2657273ac9b36264fb8d255879c18f77, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
radius: 2
|
||||
intensity: 0
|
||||
registerOnStart: 0
|
||||
offset: {x: 0, y: 0, z: 0}
|
||||
followTarget: {fileID: 0}
|
||||
enableFlicker: 0
|
||||
flickerSpeed: 5
|
||||
flickerAmount: 0.2
|
||||
--- !u!1 &4009308812223849510
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -228,6 +228,8 @@ GameObject:
|
||||
- component: {fileID: 350980459442417952}
|
||||
- component: {fileID: 1893771889199554109}
|
||||
- component: {fileID: -5656676190252742350}
|
||||
- component: {fileID: 6969882061894587196}
|
||||
- component: {fileID: -1957995423241171023}
|
||||
m_Layer: 6
|
||||
m_HasEditorInfo: 1
|
||||
m_Name: Enemy3
|
||||
@@ -390,7 +392,7 @@ MonoBehaviour:
|
||||
maxHealth: 3
|
||||
deathEffect: {fileID: 0}
|
||||
isPlayer: 0
|
||||
dissolveMaterial: {fileID: 0}
|
||||
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
|
||||
fadeDuration: 2
|
||||
--- !u!114 &1893771889199554109
|
||||
MonoBehaviour:
|
||||
@@ -428,6 +430,41 @@ MonoBehaviour:
|
||||
disableOutline: 0
|
||||
outlineColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
outlineWidth: 5
|
||||
--- !u!114 &6969882061894587196
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 02ab9f3c1d1d97248b596a5863684b6c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
lightDuration: 3
|
||||
lightRadius: 3
|
||||
lightIntensity: 0.8
|
||||
--- !u!114 &-1957995423241171023
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2657273ac9b36264fb8d255879c18f77, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
radius: 2
|
||||
intensity: 0
|
||||
registerOnStart: 0
|
||||
offset: {x: 0, y: 0, z: 0}
|
||||
followTarget: {fileID: 0}
|
||||
enableFlicker: 0
|
||||
flickerSpeed: 5
|
||||
flickerAmount: 0.2
|
||||
--- !u!1 &3239335530067427485
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -316,6 +316,8 @@ GameObject:
|
||||
- component: {fileID: 350980459442417952}
|
||||
- component: {fileID: 1893771889199554109}
|
||||
- component: {fileID: -2147681641094033328}
|
||||
- component: {fileID: 4219260140172574508}
|
||||
- component: {fileID: -3573525489034336894}
|
||||
m_Layer: 6
|
||||
m_HasEditorInfo: 1
|
||||
m_Name: Enemy4
|
||||
@@ -478,7 +480,7 @@ MonoBehaviour:
|
||||
maxHealth: 3
|
||||
deathEffect: {fileID: 0}
|
||||
isPlayer: 0
|
||||
dissolveMaterial: {fileID: 0}
|
||||
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
|
||||
fadeDuration: 2
|
||||
--- !u!114 &1893771889199554109
|
||||
MonoBehaviour:
|
||||
@@ -516,6 +518,41 @@ MonoBehaviour:
|
||||
disableOutline: 0
|
||||
outlineColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
outlineWidth: 5
|
||||
--- !u!114 &4219260140172574508
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 02ab9f3c1d1d97248b596a5863684b6c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
lightDuration: 3
|
||||
lightRadius: 3
|
||||
lightIntensity: 0.8
|
||||
--- !u!114 &-3573525489034336894
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2657273ac9b36264fb8d255879c18f77, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
radius: 2
|
||||
intensity: 0
|
||||
registerOnStart: 0
|
||||
offset: {x: 0, y: 0, z: 0}
|
||||
followTarget: {fileID: 0}
|
||||
enableFlicker: 0
|
||||
flickerSpeed: 5
|
||||
flickerAmount: 0.2
|
||||
--- !u!1 &8348150211127470280
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -228,6 +228,8 @@ GameObject:
|
||||
- component: {fileID: 350980459442417952}
|
||||
- component: {fileID: 1893771889199554109}
|
||||
- component: {fileID: 3343332957993953616}
|
||||
- component: {fileID: -7192039991189473298}
|
||||
- component: {fileID: -2612511509138086723}
|
||||
m_Layer: 6
|
||||
m_HasEditorInfo: 1
|
||||
m_Name: Enemy5
|
||||
@@ -390,7 +392,7 @@ MonoBehaviour:
|
||||
maxHealth: 3
|
||||
deathEffect: {fileID: 0}
|
||||
isPlayer: 0
|
||||
dissolveMaterial: {fileID: 0}
|
||||
dissolveMaterial: {fileID: 2100000, guid: a2207e01903058a4198862e6a7fb73c7, type: 2}
|
||||
fadeDuration: 2
|
||||
--- !u!114 &1893771889199554109
|
||||
MonoBehaviour:
|
||||
@@ -428,6 +430,41 @@ MonoBehaviour:
|
||||
disableOutline: 0
|
||||
outlineColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
outlineWidth: 5
|
||||
--- !u!114 &-7192039991189473298
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 02ab9f3c1d1d97248b596a5863684b6c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
lightDuration: 3
|
||||
lightRadius: 3
|
||||
lightIntensity: 0.8
|
||||
--- !u!114 &-2612511509138086723
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2150025513644625521}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2657273ac9b36264fb8d255879c18f77, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
radius: 2
|
||||
intensity: 0
|
||||
registerOnStart: 0
|
||||
offset: {x: 0, y: 0, z: 0}
|
||||
followTarget: {fileID: 0}
|
||||
enableFlicker: 0
|
||||
flickerSpeed: 5
|
||||
flickerAmount: 0.2
|
||||
--- !u!1 &7767081684170806371
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Reference in New Issue
Block a user