
场景【第一关】 1.添加事件【打完电码后】,包含以下内容: (1.关闭电报机界面 (2.在玩家周围生成一颗导弹 (3.导弹炸不到玩家,但是仍触发玩家被炸死的动画,表示被震晕 (4.震晕动画结束后若干秒,屏幕全黑 (5.转移到场景【第二关】 场景【第二关】 1.替换场景美术素材 2.将场景翻转 3.布置电报机 4.布置电报线 5.创建对话【醒来】,使其在改场景一开始就触发 6.给损坏的电报机添加代码,使玩家跟电报机互动后,电报机背在身上。 7.创建事件【若没拿包】,当玩家走到坡的一半并且没有拿损坏的电报机触发,弹出对话要求玩家拿电报机 8.创建对话【还没拿包】 9.修改地形 10.布置碉堡灯光敌人,具有以下特性: (1.当玩家暴露在灯光下且没有模板遮挡时,判定玩家死亡 (2.碉堡的灯每若干秒都会过热关闭一段事件 11.安排坑的上下坑功能
112 lines
3.2 KiB
C#
112 lines
3.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class NightBlockHouse : MonoBehaviour
|
||
{
|
||
// Start is called before the first frame update
|
||
//晚上的碉堡类
|
||
//碉堡类敌人的控制代码
|
||
|
||
[Tooltip("请填入开枪的间隔时间")]
|
||
public float firingInterval;
|
||
private ShootingArea[] shootingAreas;
|
||
private bool isShooting = false;//记录此时自己是否正在射击
|
||
[Tooltip("请拖入两灯游戏物体")]
|
||
public GameObject[] lights;
|
||
|
||
void Start()
|
||
{
|
||
shootingAreas = new ShootingArea[transform.childCount];
|
||
for(int i = 0; i < transform.childCount; i++)
|
||
{
|
||
shootingAreas[i] = transform.GetChild(i).
|
||
gameObject.AddComponent<ShootingArea>();//给每个子物体挂上射击区的脚本
|
||
//并且把它的脚本送到数组里面,免去以后再遍历拖慢速度
|
||
}
|
||
InvokeRepeating("ShootOrStopShoot",firingInterval,firingInterval);
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
if(isShooting) Shooting();//如果正在射击,每帧检查射击区
|
||
}
|
||
|
||
// void OnTriggerEnter2D(Collider2D other)
|
||
// {
|
||
// if(other.tag == "Player")
|
||
// {
|
||
// //当玩家进入监视区,开始每隔时间进行扫射
|
||
// InvokeRepeating("ShootOrStopShoot",firingInterval,firingInterval);
|
||
// }
|
||
// }
|
||
|
||
// void OnTriggerExit2D(Collider2D other)
|
||
// {
|
||
// if(other.tag == "Player")
|
||
// {
|
||
// //当玩家退出监视区,取消扫射的Invoke
|
||
// CancelInvoke("ShootOrStopShoot");
|
||
// }
|
||
|
||
|
||
// }
|
||
|
||
//定时触发,反正就是更改射击状态,射到不射或者不射到射
|
||
private void ShootOrStopShoot()
|
||
{
|
||
if(isShooting)//如果在开火
|
||
{
|
||
isShooting = false;//别让它开了
|
||
foreach(GameObject light in lights)
|
||
{
|
||
light.SetActive(false);
|
||
}
|
||
}
|
||
else//如果没在开火
|
||
{
|
||
isShooting = true;//标记让它开火
|
||
foreach(GameObject light in lights)
|
||
{
|
||
light.SetActive(true);
|
||
}
|
||
}
|
||
}
|
||
//正在射击的时候触发,每帧检测是否被击中
|
||
private void Shooting()
|
||
{
|
||
foreach(ShootingArea s in shootingAreas)
|
||
{
|
||
if(s.IsPlayerHere())
|
||
{
|
||
Debug.Log("玩家被击中!");
|
||
}
|
||
}
|
||
}
|
||
|
||
private class ShootingArea : MonoBehaviour
|
||
{
|
||
//射击区类,我懒得再单写一个脚本了,里面东西很少
|
||
private bool isPlayerHere = false;//记录玩家是否在内部
|
||
|
||
void OnTriggerEnter2D(Collider2D other)
|
||
{
|
||
if(other.tag == "Player")
|
||
{
|
||
//当玩家进入射击区,更改判断标志
|
||
isPlayerHere = true;
|
||
}
|
||
}
|
||
void OnTriggerExit2D(Collider2D other)
|
||
{
|
||
if(other.tag == "Player")
|
||
{
|
||
//当玩家退出射击区,更改判断标志
|
||
isPlayerHere = false;
|
||
}
|
||
}
|
||
|
||
public bool IsPlayerHere(){return isPlayerHere;}//返回玩家是否在这个射击区内的结果
|
||
}
|
||
}
|