怪物受击变色,僵直,飘字放大,残血屏幕红色闪烁

This commit is contained in:
GL 2024-12-16 17:46:38 +08:00
parent d560ce058d
commit 3f8f429755
9 changed files with 214 additions and 14 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3505deed66e44ef41a159e967ee2ce63
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,95 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2313792537985532392
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2313792537985532393}
- component: {fileID: 2313792537985532395}
- component: {fileID: 2313792537985532394}
- component: {fileID: 6226988956929044369}
m_Layer: 5
m_Name: RedMask
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2313792537985532393
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2313792537985532392}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 1080, y: 1920}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2313792537985532395
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2313792537985532392}
m_CullTransparentMesh: 1
--- !u!114 &2313792537985532394
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2313792537985532392}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &6226988956929044369
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2313792537985532392}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: da0230a1ec2c3a447b762a42b559e28f, type: 3}
m_Name:
m_EditorClassIdentifier:
screenEdgeImage: {fileID: 2313792537985532394}
flashDuration: 1
flashColor: {r: 1, g: 0, b: 0, a: 0.5}
flashInterval: 1

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c4180378f5c580d439d8089a4ec25cb2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -70,7 +70,7 @@ MonoBehaviour:
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 200
m_FontStyle: 0
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 200
@ -95,7 +95,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
minScale: {x: 2, y: 2, z: 2}
maxScale: {x: 2.5, y: 2.5, z: 2.5}
duration: 1
duration: 0.5
moveSpeed: 0.5
fadeDuration: 0
moveDistance: 1

View File

@ -5,10 +5,10 @@ public class SnowHpControl : MonoBehaviour
{
public Vector3 minScale = new Vector3(0f, 0.1f, 1f); // 最小缩放
public Vector3 maxScale = new Vector3(1f, 0.1f, 1f); // 最大缩放
public float duration = 1f; // 从min到max的时间
public float duration = 1f; // 移动和缩放的持续时间
public float moveSpeed = 0.005f; // 向上飘动的速度
public float fadeDuration = 0f; // 消失时间(设置为零实现即时消失)
public float moveDistance = 2f; // 向上飘动的最大距离
public float moveDistance = 1f; // 向上飘动的最大距离
public Canvas targetCanvas; // 目标画布用于确保UI元素在该画布上移动
private Renderer rend; // 用于获取物体的Renderer来控制透明度
@ -36,11 +36,29 @@ public class SnowHpControl : MonoBehaviour
// 初始化血条的缩放
transform.localScale = minScale;
// 使用DOTween做缩放动画,从最小缩放到最大缩放
transform.DOScale(maxScale, duration).SetEase(Ease.InOutQuad).OnComplete(StartFading);
// 使用DOTween做移动和缩放动画移动过程中从minScale逐渐变大
Sequence sequence = DOTween.Sequence();
// 启动血条向上飘动的动画(从初始位置向上移动 `moveDistance` 单位)
transform.DOMoveY(initialPosition.y + moveDistance, duration).SetEase(Ease.InOutQuad);
// 1. 先移动的过程中从minScale逐渐变大到maxScale
sequence.Append(transform.DOMoveY(initialPosition.y + moveDistance, 0.3f)
.SetEase(Ease.InOutQuad) // 移动动画
);
sequence.Join(transform.DOScale(maxScale, 0.3f)
.SetEase(Ease.InOutQuad) // 同步缩放动画从minScale到maxScale
);
// 2. 到达终点后物体放大比maxScale大
sequence.Append(transform.DOScale(maxScale * 1.5f, 0.3f)
.SetEase(Ease.OutBack) // 终点放大使用OutBack使得放大更明显
);
//// 3. 缩回到maxScale
//sequence.Append(transform.DOScale(maxScale, 0.3f)
// .SetEase(Ease.InOutQuad) // 缩回时使用InBack使得动画自然
//);
// 4. 动画完成后进行消失动画
sequence.OnComplete(() => StartFading());
}
private void StartFading()

View File

@ -157,7 +157,7 @@ MonoBehaviour:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
moveSpeed: 1
moveSpeed: 3
obj: {fileID: 4703411402842800732}
--- !u!114 &4703411402755586929
MonoBehaviour:
@ -180,7 +180,7 @@ MonoBehaviour:
Hpfiil: {fileID: 6236648196338733329}
HpTextPrefab: {fileID: 6292166076641120080, guid: 4a7236e471dd72b4299671c7330ec483, type: 3}
_Canvas: {fileID: 4205844203331515742}
zhanhunPrefab: {fileID: 6697713946806966764, guid: b1a4ddbbc3a518644bab6bfb25cb7851, type: 3}
spriteRenderers: {fileID: 4703411402842800734}
gold: 10
physicalArmor: 10
magicArmor: 5
@ -225,7 +225,7 @@ MonoBehaviour:
- {fileID: 21300000, guid: 84ea23eac94f8e84bb75e7c77f95447e, type: 3}
- {fileID: 21300000, guid: cab320b3f45281448944a1a9c46cc762, type: 3}
- {fileID: 21300000, guid: 1657ff3f38d87b94586a400f5834025c, type: 3}
CharacterAnimationFrameInterval: 50
CharacterAnimationFrameInterval: 12
- value:
- {fileID: 21300000, guid: d0e97f96cf7eb544ab3a5fa66cd90b76, type: 3}
- {fileID: 21300000, guid: d5d7283b4ed2eb84d8c769594f12ea17, type: 3}
@ -241,7 +241,7 @@ MonoBehaviour:
- {fileID: 21300000, guid: d354dd3eb7053324f97e19f4e8806045, type: 3}
- {fileID: 21300000, guid: 6bae05c1b7ed03044aa4498f65b75b98, type: 3}
- {fileID: 21300000, guid: f4b340d40b92169439104e91216e7f6e, type: 3}
CharacterAnimationFrameInterval: 50
CharacterAnimationFrameInterval: 12
animationHighlight: 0
spriteRenderer: {fileID: 4703411402842800734}
image: {fileID: 0}
@ -427,7 +427,7 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 81f10bc693229ec44be331839e6d7d27, type: 3}
m_Sprite: {fileID: 21300000, guid: e0e86e375a0004c47b26c1510431b4ab, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0

View File

@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class ScreenFlashEffect : MonoBehaviour
{
public Image screenEdgeImage; // 用于显示闪烁的UI元素整个屏幕的边缘效果
public float flashDuration = 1f; // 每次闪烁的持续时间
public Color flashColor = new Color(1f, 0f, 0f, 0.5f); // 红色透明的渐变颜色
public float flashInterval = 1f; // 闪烁间隔比如每隔0.5秒闪烁一次)
void Update()
{
if (Input.GetKeyDown(KeyCode.P)) //
{
StartFlashing();
}
else if (Input.GetKeyDown(KeyCode.I)) //
{
StopFlashing();
}
}
private void Start()
{
// 初始化透明状态
screenEdgeImage.color = new Color(0, 0, 0, 0); // 初始透明
}
public void StartFlashing()
{
// 使用DOTween做循环闪烁动画
Sequence sequence = DOTween.Sequence();
// 1. 渐变到红色
sequence.Append(screenEdgeImage.DOColor(flashColor, flashDuration).SetEase(Ease.InOutQuad));
// 2. 再渐变回透明
sequence.Append(screenEdgeImage.DOColor(new Color(0, 0, 0, 0), flashDuration).SetEase(Ease.InOutQuad));
// 3. 循环闪烁
sequence.SetLoops(-1, LoopType.Yoyo); // 无限次循环往返动画Yoyo
}
public void StopFlashing()
{
// 取消闪烁效果
screenEdgeImage.color = new Color(0, 0, 0, 0); // 恢复透明
DOTween.Kill(screenEdgeImage); // 停止所有DOTween动画
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da0230a1ec2c3a447b762a42b559e28f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -133,10 +133,18 @@ public class SkillBox : Base
{
//生成预制体并设置初始位置
GameObject expObj = Instantiate(zhanhunPrefab,pos.position, Quaternion.identity);
//expObj.transform.localScale = Vector3.zero;
//CreateAni(expObj);
ShakeAndMoveToExpSlot(expObj, pos.position, amount);
}
// 物体生成动画
private void CreateAni(GameObject expObj)
{
expObj.transform.DOScale(new Vector3(1, 1, 1), 0.5f).SetEase(Ease.InBack);
}
// 物体摆动并飞到经验槽
private void ShakeAndMoveToExpSlot(GameObject expObj, Vector3 spawnPosition, int amount)