diff --git a/Assets/MyPostProcess/Effects/Wave/Attack_Wave/AWM0.mat b/Assets/MyPostProcess/Effects/Wave/Attack_Wave/AWM0.mat index 2d5b9db..ea1cedf 100644 --- a/Assets/MyPostProcess/Effects/Wave/Attack_Wave/AWM0.mat +++ b/Assets/MyPostProcess/Effects/Wave/Attack_Wave/AWM0.mat @@ -42,8 +42,8 @@ Material: - WaveCount: 50 - WaveIntensity_1: 0.02 - WaveIntensity_2: 1 - - WaveSpread_Value: 6.399998 + - WaveSpread_Value: 0 m_Colors: - - Center: {r: 0.6742085, g: 0.2503847, b: 0, a: 0} + - Center: {r: 0.13730037, g: 0.24812932, b: 0, a: 0} - Vector2_d2d098295fc146f08b921b231b2e5199: {r: 1.6, g: 0.9, b: 0, a: 0} m_BuildTextureStacks: [] diff --git a/Assets/Scenes/各种系统测试与陈列.unity b/Assets/Scenes/各种系统测试与陈列.unity index d427f44..7a82253 100644 --- a/Assets/Scenes/各种系统测试与陈列.unity +++ b/Assets/Scenes/各种系统测试与陈列.unity @@ -2429,7 +2429,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 788577770} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -28.36, y: -1.06, z: 0} + m_LocalPosition: {x: -27.07, y: -1.06, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 293805376} @@ -2763,8 +2763,9 @@ MonoBehaviour: m_EditorClassIdentifier: point1: {fileID: 788577771} point2: {fileID: 1209357885} - walkSpeed: 0 - rushSpeed: 1 + walkSpeed: 5 + rushSpeed: 10 + speed: 0 missiles: [] --- !u!1 &969830747 GameObject: @@ -2983,7 +2984,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1209357884} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -15.22, y: -0.55, z: 0} + m_LocalPosition: {x: -19.31, y: -0.55, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 293805376} @@ -5495,7 +5496,7 @@ BoxCollider2D: adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 - m_Size: {x: 1.45, y: 1.1} + m_Size: {x: 3.8, y: 1.1} m_EdgeRadius: 0 --- !u!1001 &1936744432 PrefabInstance: @@ -6527,7 +6528,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8233114533063075529, guid: 82d871be611f9d14fbe8c166075c1a37, type: 3} propertyPath: m_AnchoredPosition.y - value: -3.9000626 + value: -3.900055 objectReference: {fileID: 0} - target: {fileID: 8233114533063075529, guid: 82d871be611f9d14fbe8c166075c1a37, type: 3} propertyPath: m_LocalEulerAnglesHint.x diff --git a/Assets/Scripts/具象物体/Missile.cs b/Assets/Scripts/具象物体/Missile.cs index d4af25c..24e77aa 100644 --- a/Assets/Scripts/具象物体/Missile.cs +++ b/Assets/Scripts/具象物体/Missile.cs @@ -6,6 +6,8 @@ public class Missile : MonoBehaviour { //投掷物类,用来控制投掷物 // Start is called before the first frame update + private bool amINoisy = false;//记录自己是否落地发出声音的变量 + private bool amIBeenChecked = false;//记录自己是否已经被敌人检查过 void Start() { @@ -16,4 +18,21 @@ public class Missile : MonoBehaviour { } + + void OnCollisionEnter2D(Collision2D other) + { + if(other.gameObject.tag == "地面") + { + //当投掷物砸到地面,发出一个响声(逻辑上),标记自身为声源 + amINoisy = true; + //同时,摧毁自身的刚体组件,阻止其滚动 + Destroy(GetComponent()); + //再摧毁自身碰撞体 + Destroy(GetComponent()); + } + } + + public bool AMINoisy(){return amINoisy;} + public bool AmIBeenChecked(){return amIBeenChecked;} + public void YouAreChecked(){amIBeenChecked = true;} } diff --git a/Assets/Scripts/具象物体/Patrolman.cs b/Assets/Scripts/具象物体/Patrolman.cs index f177fd0..4e43805 100644 --- a/Assets/Scripts/具象物体/Patrolman.cs +++ b/Assets/Scripts/具象物体/Patrolman.cs @@ -15,6 +15,7 @@ public class Patrolman : MonoBehaviour public float walkSpeed; [Tooltip("听见响动,冲锋时的速度")] public float rushSpeed; + [SerializeField][ReadOnly] private float speed;//记录此刻瞬间的速度,不包含方向 private float velocity;//速度,正值代表向右,用来判断面部朝向 private Transform target;//当前目标位置 @@ -38,6 +39,25 @@ public class Patrolman : MonoBehaviour void Update() { Move();//每帧朝目标移动 + CheckMissiles();//检查是否有投掷物落地 + } + + private void CheckMissiles() + { + foreach(Missile missile in missiles) + { + if(missile.AMINoisy() && !missile.AmIBeenChecked())//如果投掷物在发声、且没有被检查过 + { + //将目标位置设定为落点 + target = missile.transform; + //更改速度为跑步速度 + speed = rushSpeed; + //标记该投掷物已被检查 + missile.YouAreChecked(); + isInterrupt = true; + PVelocity = 0; + } + } } //朝目标移动函数 @@ -48,12 +68,23 @@ public class Patrolman : MonoBehaviour velocity = Mathf.Abs(velocity)/velocity;//把速度标准化为1或者-1,只保留方向 velocity *= speed;//给速度赋以大小 - //判断是否到达巡逻点 - if(velocity*PVelocity < 0 && !isInterrupt)//速度相乘得负数,说明方向发生改变 + //判断是否到达巡逻点或者落点 + if(velocity*PVelocity < 0)//速度相乘得负数,说明方向发生改变 { //如果计算速度发生改变,且不是因为被石头打断,说明经过了巡逻点,此时更换目标点为另一个 - if(target.Equals(point1)) target = point2; - else target = point1; + if(target.Equals(point1) && !isInterrupt) target = point2; + else if(target.Equals(point2) && !isInterrupt) target = point1;//不是被投掷物吸引的时候,才这样 + + //如果目标是投掷物的落点,恢复速度和目标点 + if(target.gameObject.tag == "投掷物") + { + speed = walkSpeed; + //target = point2; + if(velocity > 0) target = point2; + else target = point1; + Debug.Log("投掷物触发转向"); + isInterrupt = false; + } } //控制面部朝向 @@ -74,6 +105,7 @@ public class Patrolman : MonoBehaviour //更新PVelocity PVelocity = velocity; + } void OnTriggerEnter2D(Collider2D other) @@ -85,13 +117,6 @@ public class Patrolman : MonoBehaviour public void AddAMissile(Missile missile){missiles.Add(missile);} //在听觉范围中调用,移除一个监听中的投掷物 public void RemoveAMissile(Missile missile){missiles.Remove(missile);} - // for(int i = 0; i < missiles.Count; i++) - // { - // if(missiles[i].Equals(missile)) - // { - // missiles.Remove(missile); - // } - // }