Roman 3c682117f3 任务:搭建第一关的框架
场景【第一关】
1.加入任务书的交互,交互键打开任务书,键盘【K】退出、手柄【B】退出
2.加入轰炸区、并做好适配。
3.啧,由于轰炸区的高度写了屎山代码,现在只能把对高度的适配这个参数还给轰炸区,再在场景中的轰炸区进行适配。
4.布置电话线断处(共六处)
5.优化电话线断除脚本,使其能够自己找到修电话线的UI
6.给电话线断处加上结束事件,因为有一条电话线修好后需要炸毁前面的石头
7.创建游戏物体【石头】
8.给石头添加控制脚本。
9.创建并编写事件【当修好第一个电话线】,召唤一枚炮弹砸向石头,石头检测到炮弹后销毁自己和炮弹,并在原地生成一个投掷物堆。
10.给炮弹加上标识,不是特殊的炮弹砸不烂石头。

下班,就剩9天了……😔
2021-08-18 00:50:19 +08:00

77 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BombingArea : MonoBehaviour
{
//这是轰炸区的脚本,控制轰炸区相关的所有逻辑💣
// Start is called before the first frame update
private bool bombing = false;//是否正在轰炸
public GameObject shell;//炮弹游戏物体
[Tooltip("炮弹阴影Y轴的偏移量")]
public float shellShadowYOffset;//炮弹阴影Y轴的偏移量因为复杂原因必须使用此变量调整阴影的Y位置
private float minimumTimeInterval;
private float maximumTimeInterval;//生成炮弹的最小和最大时间间隔
private float maxOffSetOfShell;//生成炮弹离玩家的最大偏移量
private float leftTime = 0f;
private IndexRecoder indexRecoder;
private M_Player player;
private float shellHeight;
void Start()
{
Init();
}
// Update is called once per frame
void Update()
{
if(bombing) Bomb();
}
private void Init()
{
indexRecoder = FindObjectOfType<IndexRecoder>();
minimumTimeInterval = indexRecoder.bombingAreaMinimumTimeInterval;
maximumTimeInterval = indexRecoder.bombingAreaMaximumTimeInterval;
maxOffSetOfShell = indexRecoder.bombingAreaMaxOffSetOfShell;
shellHeight = indexRecoder.bombingAreaShellHeight;
player = FindObjectOfType<M_Player>();
}
private void Bomb()
{
if(leftTime <= 0f)
{
GameObject ThisShell = Instantiate(shell,//生成炮弹
player.transform.position + //以玩家位置
new Vector3(Random.Range(-maxOffSetOfShell,maxOffSetOfShell),//加上水平方向的偏移量
shellHeight,0),//竖直方向给高度
Quaternion.identity);
ThisShell.GetComponent<Shell>().M_BombingArea = this;//给子弹赋以自身让其好获取Y轴偏移量
leftTime = Random.Range(minimumTimeInterval,maximumTimeInterval);
}
else leftTime -= Time.deltaTime;
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")//当玩家进入轰炸区
{
bombing = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if(other.tag == "Player")//当玩家退出轰炸区
{
bombing = false;
}
}
}