2022-07-28 15:58:55 +08:00
|
|
|
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;
|
2022-08-27 21:30:16 +08:00
|
|
|
private Transform mountain1;
|
|
|
|
private Transform mountain2;
|
|
|
|
|
|
|
|
public float mountain1Speed = 0.5f;
|
|
|
|
public float mountain2Speed = 0.8f;
|
2022-07-28 15:58:55 +08:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
InitSth();
|
|
|
|
FindSth();
|
|
|
|
CreatSth();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
//向右移动镜头
|
2022-08-27 21:30:16 +08:00
|
|
|
Move();
|
|
|
|
//移动远山
|
|
|
|
MoveMountain();
|
2022-07-28 15:58:55 +08:00
|
|
|
}
|
|
|
|
|
2022-08-27 21:30:16 +08:00
|
|
|
private void MoveMountain(){
|
|
|
|
mountain1.Translate(Vector3.left * mountain1Speed * Time.deltaTime);
|
|
|
|
mountain2.Translate(Vector3.left * mountain2Speed * Time.deltaTime);
|
|
|
|
if(mountain1.localPosition.x < -140) mountain1.localPosition = new Vector3(140, -6.8f, 1);
|
|
|
|
if(mountain2.localPosition.x < -140) mountain2.localPosition = new Vector3(140, -6.8f, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-28 15:58:55 +08:00
|
|
|
public void Death(GameController.Death deathInfo)
|
|
|
|
{
|
|
|
|
//相机不再运动
|
|
|
|
speed = 0;
|
2022-08-27 21:30:16 +08:00
|
|
|
//远景不再运动
|
|
|
|
mountain1Speed = 0;
|
|
|
|
mountain2Speed = 0;
|
2022-07-28 15:58:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreatSth()
|
|
|
|
{
|
|
|
|
killWall.gameObject.AddComponent<KillWall>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindSth()
|
|
|
|
{
|
|
|
|
killWall = transform.Find("KillWall");
|
|
|
|
//killWall = GameObject.Find("KillWall").transform;
|
|
|
|
if(killWall == null) Debug.LogError("没找到KillWall,请检查相机是否有叫此名字的子物体");
|
2022-08-27 21:30:16 +08:00
|
|
|
mountain1 = transform.Find("远景1");
|
|
|
|
mountain2 = transform.Find("远景2");
|
2022-07-28 15:58:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2022-07-30 00:47:44 +08:00
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D other) {
|
2022-08-19 14:23:35 +08:00
|
|
|
//Debug.Log("出去了一个:" + other.name);
|
2022-07-30 00:47:44 +08:00
|
|
|
switch(other.tag)
|
|
|
|
{
|
|
|
|
case "Fragment":
|
|
|
|
Destroy(other.gameObject);
|
|
|
|
break;
|
|
|
|
case "Obstacle":
|
|
|
|
Destroy(other.gameObject);
|
|
|
|
break;
|
2022-07-30 20:02:28 +08:00
|
|
|
case "Right" :
|
|
|
|
other.transform.parent.position += new Vector3(1,0,0) * 230f;
|
|
|
|
break;
|
2022-07-30 00:47:44 +08:00
|
|
|
}
|
2022-07-30 20:02:28 +08:00
|
|
|
|
|
|
|
if(other.gameObject.layer == LayerMask.NameToLayer("Fragment"))
|
|
|
|
Destroy(other.gameObject);
|
2022-07-30 00:47:44 +08:00
|
|
|
}
|
2022-07-28 15:58:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|