2022-07-30 00:47:44 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-08-19 14:23:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 人马分离障碍物类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class HumanHorseBreakObstacle : Obstacle
|
2022-07-30 00:47:44 +08:00
|
|
|
|
{
|
2022-08-19 14:23:35 +08:00
|
|
|
|
bool hasShoot = false;
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D other) {
|
|
|
|
|
//如果人进入了人马分离的触发器,触发人的发射函数
|
|
|
|
|
if(other.TryGetComponent<Person>(out Person person) && !hasShoot) {person.Shoot();hasShoot = true;}
|
2022-07-30 00:47:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 14:23:35 +08:00
|
|
|
|
private void OnCollisionEnter2D(Collision2D other) {
|
|
|
|
|
//如果人到了平台上,触发Walk
|
|
|
|
|
if(other.gameObject.TryGetComponent<Person>(out Person person) && person.state == Person.PersonState.Shoot) {person.Walk();}
|
2022-07-30 00:47:44 +08:00
|
|
|
|
}
|
2022-08-19 14:23:35 +08:00
|
|
|
|
|
|
|
|
|
private void OnCollisionExit2D(Collision2D other) {
|
|
|
|
|
//如果人离开了平台上,触发FallingOff
|
|
|
|
|
if(other.gameObject.TryGetComponent<Person>(out Person person) && person.state == Person.PersonState.Walk) {person.FallingOff();}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-30 00:47:44 +08:00
|
|
|
|
}
|