diff --git a/Assets/Scenes/test.unity b/Assets/Scenes/test.unity index 97f91cc..bce5d6d 100644 --- a/Assets/Scenes/test.unity +++ b/Assets/Scenes/test.unity @@ -363,14 +363,14 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 321454205} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: 0, y: 0, z: -1, w: 0} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 2098309883} m_Father: {fileID: 326335323} m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: -180} --- !u!114 &321454207 MonoBehaviour: m_ObjectHideFlags: 0 @@ -429,7 +429,7 @@ MonoBehaviour: targetGO: {fileID: 0} tweenTargetIsTargetGO: 1 delay: 0 - duration: 0.5 + duration: 0.25 easeType: 1 easeCurve: serializedVersion: 2 @@ -472,7 +472,7 @@ MonoBehaviour: autoPlay: 0 useTargetAsV3: 0 endValueFloat: 0 - endValueV3: {x: 0, y: 0, z: -90} + endValueV3: {x: 0, y: 0, z: -1} endValueV2: {x: 0, y: 0} endValueColor: {r: 1, g: 1, b: 1, a: 1} endValueString: @@ -747,6 +747,7 @@ MonoBehaviour: sickleCDLeft: 0 inControl: 1 HPLeft: 0 + isCatching: 0 --- !u!95 &326335328 Animator: serializedVersion: 3 @@ -1219,6 +1220,7 @@ MonoBehaviour: ATK: 1 speed: 1 coin: 0 + canBeHit: 1 HPLeft: 0 state: 0 hitToflyParameter: {x: 3, y: 3} @@ -1226,7 +1228,7 @@ MonoBehaviour: deadRotationRangeMin: 500 inPath: 1 catchOffset: {x: 0, y: 0, z: 0} - breakFreeCount: 1 + breakFreeCount: 5 breakFreeCountLeft: 0 --- !u!1 &839378814 GameObject: @@ -1840,6 +1842,7 @@ MonoBehaviour: ATK: 1 speed: 1 coin: 0 + canBeHit: 1 HPLeft: 0 state: 0 hitToflyParameter: {x: 3, y: 3} @@ -2048,7 +2051,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2098309882} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1.306, z: 0} + m_LocalPosition: {x: 0, y: 0.44, z: 0} m_LocalScale: {x: 0.1875, y: 1.2, z: 1} m_Children: [] m_Father: {fileID: 321454206} @@ -2093,9 +2096,9 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 0 + m_SortingOrder: 1 m_Sprite: {fileID: 7482667652216324306, guid: 48e93eef0688c4a259cb0eddcd8661f7, type: 3} - m_Color: {r: 1, g: 1, b: 1, a: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 @@ -2112,7 +2115,7 @@ BoxCollider2D: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2098309882} - m_Enabled: 0 + m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} m_IsTrigger: 1 diff --git a/Assets/Scripts/AiYuPin.cs b/Assets/Scripts/AiYuPin.cs index 0b15aa6..1e0bae5 100644 --- a/Assets/Scripts/AiYuPin.cs +++ b/Assets/Scripts/AiYuPin.cs @@ -99,7 +99,7 @@ public class AiYuPin : NormalEnemy /// protected override void OnFindThePlayer(Transform target){ //如果没死 - if(state != State.dead) + if(state == State.wander) { //标记自身状态 state = State.seek; @@ -115,6 +115,10 @@ public class AiYuPin : NormalEnemy /// protected override void OnTouchThePlayer(MyPlayer player) { + //通知玩家,你被爱欲品附身了 + player.BeCatchedByAiYuPin(this); + //暂停Path动画 + doTweenPath.DOPause(); //改变自身状态为ATK state = State.atk; //关闭自身碰撞体,因为要贴在玩家身上 @@ -122,10 +126,10 @@ public class AiYuPin : NormalEnemy //将自身位置和玩家位置同步,但是需要一个附身offset二维向量 //因为玩家的图片不在游戏物体的中心 transform.position = target.position + catchOffset; - //通知玩家,你被爱欲品附身了 - player.BeCatchedByAiYuPin(this); //暂时清空重力系数 m_rigidbody.gravityScale = 0; + //清除一下刚体速度,不然怪物可能被创飞 + m_rigidbody.velocity = Vector2.zero; } /// @@ -139,10 +143,12 @@ public class AiYuPin : NormalEnemy OnFindThePlayer(target);//触发发现玩家事件 //执行被击飞、死亡检查等事宜 base.OnBeHit(hitMethod, hitDir); + //被打飞在着地前都不会挨打了 + canBeHit = false; } //原先会触发自动返回记录起点,但是不能,所以重写空的重新着地事件 - protected override void OnRetouchedTheGround(){} + protected override void OnRetouchedTheGround(){ canBeHit = true; } /// /// 完全挣脱的时候触发 @@ -156,13 +162,14 @@ public class AiYuPin : NormalEnemy OnDead(); //给一个击飞 BeHitToFly((Random.Range(-1f,1f) > 0) ? 1: -1); + //通知玩家 + FindObjectOfType().BreakFreeCompletely(); } /// /// 玩家尝试挣脱的时候触发这个 /// - [ContextMenu("挣脱")] - protected void OnBreakFree(){ + public void OnBreakFree(){ if(--breakFreeCountLeft <= 0) OnBreakFreeCompletely(); } diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs index 7fb8dc2..31e12e4 100644 --- a/Assets/Scripts/Enemy.cs +++ b/Assets/Scripts/Enemy.cs @@ -43,6 +43,10 @@ public class Enemy : MonoBehaviour /// 怪物拥有的几种状态 /// public enum State{wander,seek,atk,dead}; + /// + /// 此时怪物能否被攻击 + /// + public bool canBeHit = true; // _____ _ _ // | __ \ (_) | | diff --git a/Assets/Scripts/Hammer.cs b/Assets/Scripts/Hammer.cs index bd6de65..2ac8d51 100644 --- a/Assets/Scripts/Hammer.cs +++ b/Assets/Scripts/Hammer.cs @@ -9,10 +9,10 @@ public class Hammer : MonoBehaviour { //当有东西进入触发器 public void OnTriggerEnter2D(Collider2D other){ - //看看是不是敌人 - if(other.TryGetComponent(out Enemy enemy)){ - enemy.OnBeHit(MyPlayer.AtkMethod.锤子, - (enemy.transform.position.x - + //看看是不是敌人,再看下它此时能不能被打 + if (other.TryGetComponent(out Enemy enemy) && enemy.canBeHit && !other.isTrigger){ + enemy.OnBeHit(MyPlayer.AtkMethod.锤子, + (enemy.transform.position.x - transform.position.x > 0) ? -1 : 1); } } diff --git a/Assets/Scripts/MyPlayer.cs b/Assets/Scripts/MyPlayer.cs index 0eaf643..2ba7ecf 100644 --- a/Assets/Scripts/MyPlayer.cs +++ b/Assets/Scripts/MyPlayer.cs @@ -96,6 +96,15 @@ public class MyPlayer : MonoBehaviour /// 是否在攻击 /// private bool isAttacking; + /// + /// 记录此时自己是否被爱欲品缠抱 + /// + [Header("被缠抱了吗?")][SerializeField][ReadOnly][FoldoutGroup("Info")] + private bool isCatching = false; + /// + /// 正抓着玩家的爱欲品 + /// + private AiYuPin catingAiYuPin; // _____ _ _ ____ _ @@ -112,12 +121,12 @@ public class MyPlayer : MonoBehaviour void Update() { CountCD(); + ChangeAnimator(); } void FixedUpdate() { - Move();//处理水平移动 - ChangeAnimator(); + Move();//处理水平移动 } // _ _ _ @@ -153,7 +162,7 @@ public class MyPlayer : MonoBehaviour //移动函数,处理水平方向移动 private void Move() { - if(inControl){ + if(inControl && !isAttacking){ //直接修改刚体速度 m_rigidbody.velocity = new Vector2(inputDir * speed,//水平方向以输入方向乘以预设速度大小 m_rigidbody.velocity.y);//垂直方向不变 @@ -191,7 +200,7 @@ public class MyPlayer : MonoBehaviour } /// - /// 每FixedUpdate调用,处理状态机全部放这里 + /// 每Update调用,处理状态机全部放这里 /// protected void ChangeAnimator() { @@ -213,6 +222,13 @@ public class MyPlayer : MonoBehaviour //被击飞动画触发 m_Animator.SetBool("isBeHitting",!inControl); } + + /// + /// 被爱欲品抓住时用协程触发 + /// + private void CatchingHarm(){ + HPLeft -= FindObjectOfType().ATK; + } //碰撞检测代码 // _____ _ _ _ _ // / ____| | | (_) (_) @@ -224,7 +240,7 @@ public class MyPlayer : MonoBehaviour { if(collision.transform.tag == "地面") {isLanding = true;//若碰撞物体标签为地面,标记自身着地 - inControl = true;} + if(!isCatching)inControl = true;} } private void OnCollisionExit2D(Collision2D collision)//当有碰撞体离开 { @@ -249,7 +265,8 @@ public class MyPlayer : MonoBehaviour else inputDir = 0; if(faceDir * inputDir < 0){ - TurnAround(); + if(inControl)TurnAround(); + if(isCatching){catingAiYuPin.OnBreakFree();} } } @@ -258,7 +275,7 @@ public class MyPlayer : MonoBehaviour //当按下跳跃键 if(context.performed) { - if(isLanding){//如果当前着地 + if(isLanding && inControl){//如果当前着地 //给予自身刚体 m_rigidbody.velocity = new Vector2(m_rigidbody.velocity.x,//水平方向速度不变 jumpForce);//垂直方向给予预设跳跃速度 @@ -277,13 +294,13 @@ public class MyPlayer : MonoBehaviour hammerCollider.enabled = true;//打开锤子碰撞体 wavingAnimation.DOPlay();//播放挥动锤子动画 hammerCDLeft = hammerCD;//挥动成功,重置CD剩余时间 - isAttacking = true; + if(!isAttacking)isAttacking = true; } } public void OnSickle(InputAction.CallbackContext context) { - if(context.started && sickleCDLeft <= 0) + if(context.started && sickleCDLeft <= 0 && inControl) { Sickle sickle = Instantiate( sicklePrefab, @@ -320,8 +337,11 @@ public class MyPlayer : MonoBehaviour /// 攻击来源的方向,-1左,1右 public void OnBeHit(float atk, int dir) { + //触发一个击飞 BeHitToFly(dir); + //标记自身不受控制 inControl = false; + //掉血 HPLeft -= atk; } @@ -335,7 +355,32 @@ public class MyPlayer : MonoBehaviour /// /// 这个爱欲品的爱欲品组件 public void BeCatchedByAiYuPin(AiYuPin aiYuPin){ + //标记自身正被抓着 + isCatching = true; + //标记自身失去控制 + inControl = false; + //每秒掉血,伤害量为爱欲品的攻击力 + InvokeRepeating("CatchingHarm",0f,1f); + //去除刚体速度,防止滑行带来的位置偏移问题 + m_rigidbody.velocity = Vector2.zero; + //记录正在抓着自己的爱欲品 + catingAiYuPin = aiYuPin; + } + /// + /// 完全挣脱的时候从爱欲品Call过来 + /// + public void BreakFreeCompletely(){ + //取消被抓住的标记 + isCatching = false; + //恢复移动操控 + inControl = true; + //取消掉血协程 + CancelInvoke("CatchingHarm"); + //去掉记录着的抓住玩家的爱欲品 + catingAiYuPin = null; + //消除正在攻击状态以解决Bug + isAttacking = false; } diff --git a/Assets/Scripts/NormalEnemy.cs b/Assets/Scripts/NormalEnemy.cs index a2706f6..484c91a 100644 --- a/Assets/Scripts/NormalEnemy.cs +++ b/Assets/Scripts/NormalEnemy.cs @@ -115,6 +115,8 @@ public class NormalEnemy : Enemy //看下死了没 //死了就记录下死亡时候的面部朝向,用来做死亡翻滚效果,然后再Call一下死亡事件 if(CheckDead()) {deadDir = hitDir;OnDead();} + //被打飞了在着地前都不会挨打了 + canBeHit = false; } protected override void OnRetouchedTheGround(){ @@ -142,6 +144,7 @@ public class NormalEnemy : Enemy ((sourcePosition.x - transform.position.x > 0) ? 0:-180), transform.rotation.z); } + canBeHit = true; } protected override void OnDead() diff --git a/Assets/动画/AC/Player.controller b/Assets/动画/AC/Player.controller index 2528efc..6e29590 100644 --- a/Assets/动画/AC/Player.controller +++ b/Assets/动画/AC/Player.controller @@ -136,7 +136,10 @@ AnimatorStateTransition: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: - m_Conditions: [] + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: isAttacking + m_EventTreshold: 0 m_DstStateMachine: {fileID: 0} m_DstState: {fileID: -1583730504211193444} m_Solo: 0 @@ -146,7 +149,7 @@ AnimatorStateTransition: m_TransitionDuration: 0 m_TransitionOffset: 0 m_ExitTime: 0.75 - m_HasExitTime: 1 + m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 m_OrderedInterruption: 1 @@ -220,37 +223,37 @@ AnimatorController: m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: isJumping m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: isFalling m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: isLanding m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: isAttacking m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: isBeHitting m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -469,15 +472,18 @@ AnimatorStateTransition: - m_ConditionMode: 1 m_ConditionEvent: isAttacking m_EventTreshold: 0 + - m_ConditionMode: 2 + m_ConditionEvent: isBeHitting + m_EventTreshold: 0 m_DstStateMachine: {fileID: 0} m_DstState: {fileID: 634860784232356001} m_Solo: 0 m_Mute: 0 m_IsExit: 0 serializedVersion: 3 - m_TransitionDuration: 0.25 + m_TransitionDuration: 0 m_TransitionOffset: 0 - m_ExitTime: 0.75 + m_ExitTime: 0.75000006 m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 diff --git a/Assets/动画/AM/Player/锤子攻击.anim b/Assets/动画/AM/Player/锤子攻击.anim index 07d2412..21ff7e7 100644 --- a/Assets/动画/AM/Player/锤子攻击.anim +++ b/Assets/动画/AM/Player/锤子攻击.anim @@ -21,11 +21,11 @@ AnimationClip: - curve: - time: 0 value: {fileID: 21300000, guid: 50be5505d01b483409b02eac9d8ac8e5, type: 3} - - time: 0.083333336 + - time: 0.06666667 value: {fileID: 21300000, guid: d15b91f7b544ae944b0975da4e3c8dc5, type: 3} - - time: 0.15 + - time: 0.1 value: {fileID: 21300000, guid: 0803bd9b6a71cb74faa66ff1f629f77b, type: 3} - - time: 0.23333333 + - time: 0.16666667 value: {fileID: 21300000, guid: 238b4b39856f258489d82506f0976575, type: 3} attribute: m_Sprite path: @@ -55,7 +55,7 @@ AnimationClip: m_AdditiveReferencePoseClip: {fileID: 0} m_AdditiveReferencePoseTime: 0 m_StartTime: 0 - m_StopTime: 0.25 + m_StopTime: 0.18333334 m_OrientationOffsetY: 0 m_Level: 0 m_CycleOffset: 0 @@ -75,7 +75,7 @@ AnimationClip: m_HasGenericRootTransform: 0 m_HasMotionFloatCurves: 0 m_Events: - - time: 0.23333333 + - time: 0.18333334 functionName: StopAttacking data: objectReferenceParameter: {fileID: 11500000, guid: f563a3b3d1fe31d45bae72dd7ca265fd, type: 3}