
1.视野移动和死亡重开系统 (1.相机以一个可指定的、热更新的速度始终往右移动 (2.相机带有一个子物体,子物体带有触发器,触发器位于镜头最左端 (3.给马头添加碰撞体,用于判断镜头卡死死亡 (*.创建类:GameController,作为各种中介者使用 (4.当相机子物体的触发器检测到马头,说明马被卡死,给中介者发送信息触发死亡的一系列事件 ((1.马死后,修改马状态至死亡 ((2.相机不再移动 ((3.关闭马的碰撞体,给一个右上的速度和旋转,马模型掉出地图 (5.设置按键以调试重开,目前是按R DONE
74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 相机管理员,主要控制游戏核心玩法中,相机向右移动和卡死死法的判定
|
|
/// </summary>
|
|
public class CameraManager : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 相机移动的速度
|
|
/// </summary>
|
|
[Header("相机移动的速度")]
|
|
public float speed = 1f;
|
|
|
|
|
|
private Transform killWall;
|
|
|
|
void Start()
|
|
{
|
|
InitSth();
|
|
FindSth();
|
|
CreatSth();
|
|
}
|
|
|
|
|
|
void Update() {
|
|
//向右移动镜头
|
|
Move();
|
|
}
|
|
|
|
public void Death(GameController.Death deathInfo)
|
|
{
|
|
//相机不再运动
|
|
speed = 0;
|
|
}
|
|
|
|
void CreatSth()
|
|
{
|
|
killWall.gameObject.AddComponent<KillWall>();
|
|
}
|
|
|
|
void FindSth()
|
|
{
|
|
killWall = transform.Find("KillWall");
|
|
//killWall = GameObject.Find("KillWall").transform;
|
|
if(killWall == null) Debug.LogError("没找到KillWall,请检查相机是否有叫此名字的子物体");
|
|
}
|
|
|
|
void InitSth(){}
|
|
|
|
|
|
/// <summary>
|
|
/// 每帧调用,向右移动
|
|
/// </summary>
|
|
void Move(){
|
|
transform.position += (Vector3.right * speed * Time.deltaTime);
|
|
}
|
|
class KillWall : MonoBehaviour
|
|
{
|
|
void OnTriggerEnter2D(Collider2D other) {
|
|
if(other.tag == "HorseHead")
|
|
{
|
|
GameController.Death death;
|
|
death.deadReason = GameController.Death.DeadReason.Camera;
|
|
GameController.Instance.GameOver(death);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|