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

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

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

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

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

6.导出一版EXE供提交

7.撰写操作说明

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

93 lines
2.2 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);
}
}
void OnTriggerExit2D(Collider2D other) {
Debug.Log("出去了一个:" + other.name);
switch(other.tag)
{
case "Fragment":
Destroy(other.gameObject);
break;
case "Obstacle":
Destroy(other.gameObject);
break;
case "Right" :
other.transform.parent.position += new Vector3(1,0,0) * 230f;
break;
}
if(other.gameObject.layer == LayerMask.NameToLayer("Fragment"))
Destroy(other.gameObject);
}
}
}