
子任务:应付中期检查提交 1.替换场景元素,适配流程 DONE 2.修改大量游戏性参数,使其能玩 DONE 3.增加手柄按键以重开 DONE 4.替换障碍物美术素材 DONE 5.导出可执行文件 DONE 6.编写文档说明本次和上次的区别 DONE
60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 破碎障碍物
|
||
/// </summary>
|
||
void BreakObstacle(Transform horse)
|
||
{
|
||
explodable.explode();
|
||
float force = (horse.GetComponent<Rigidbody2D>().velocity.x + 1) * breakForce + 1;
|
||
explosionForce.force = force;
|
||
explosionForce.doExplosion(explosionForce.transform.position);
|
||
GetComponent<BoxCollider2D>().enabled = false;
|
||
|
||
horse.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
|
||
|
||
}
|
||
}
|