SAIMA/Assets//脚本/障碍物系统/BreakAbleObstacle.cs
Roman 465bb3e51b 任务:编写内容应付中期提交
1.替换部分美术素材
(1.替换新的马
(2.布置背景

2.创建教程场景,说明移动方式、跳跃方式,并陈列目前三种障碍

3.调节脚本优化控制体验

4.新建背景无限循环系统

5.调节各系统参数,使其至少能玩

6.导出一版EXE供提交

7.撰写操作说明

8.录制游戏演示
2022-07-30 20:02:28 +08:00

60 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 * breakForce + 1;
explosionForce.force = force;
explosionForce.doExplosion(explosionForce.transform.position);
GetComponent<BoxCollider2D>().enabled = false;
horse.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
}
}