2022-07-30 00:47:44 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class BreakAbleObstacle : Obstacle
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[Header("要破坏可破坏障碍物,需要多大的水平速度")]
|
|
|
|
|
public float breakSpeedThreshold = 1f;
|
|
|
|
|
|
|
|
|
|
[Header("爆破碎片飞出时有多大力")]
|
|
|
|
|
public float breakForce = 1f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Explodable explodable;
|
|
|
|
|
private ExplosionForce explosionForce;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void FindSth()
|
|
|
|
|
{
|
|
|
|
|
base.FindSth();
|
|
|
|
|
explodable = transform.Find("Obstacle").GetComponent<Explodable>();
|
|
|
|
|
explosionForce = transform.Find("Force").GetComponent<ExplosionForce>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other) {
|
|
|
|
|
if(other.tag == "HorseHead")
|
|
|
|
|
{
|
|
|
|
|
if(other.transform.parent.tag != "Horse")
|
|
|
|
|
Debug.LogWarning("用于检查可破碎障碍物的触发器捕获到了马头,但是通过马头没有找到马,很可能是马的树状结构或者tag的赋予上出了问题");
|
|
|
|
|
CheckHorseSpeed(other.transform.parent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckHorseSpeed(Transform horse)
|
|
|
|
|
{
|
|
|
|
|
if(horse.GetComponent<Rigidbody2D>().velocity.x > breakSpeedThreshold)
|
|
|
|
|
BreakObstacle(horse);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-30 20:02:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 破碎障碍物
|
|
|
|
|
/// </summary>
|
2022-07-30 00:47:44 +08:00
|
|
|
|
void BreakObstacle(Transform horse)
|
|
|
|
|
{
|
|
|
|
|
explodable.explode();
|
2022-08-19 14:23:35 +08:00
|
|
|
|
float force = horse.GetComponent<Horse>().footInputCharge * breakForce;
|
|
|
|
|
Debug.Log("Force:" + force);
|
2022-07-30 00:47:44 +08:00
|
|
|
|
explosionForce.force = force;
|
|
|
|
|
explosionForce.doExplosion(explosionForce.transform.position);
|
|
|
|
|
GetComponent<BoxCollider2D>().enabled = false;
|
2022-07-30 20:02:28 +08:00
|
|
|
|
|
|
|
|
|
horse.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
|
|
|
|
|
|
2022-07-30 00:47:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|