
场景【第一关】
1.加入任务书的交互,交互键打开任务书,键盘【K】退出、手柄【B】退出
2.加入轰炸区、并做好适配。
3.啧,由于轰炸区的高度写了屎山代码,现在只能把对高度的适配这个参数还给轰炸区,再在场景中的轰炸区进行适配。
4.布置电话线断处(共六处)
5.优化电话线断除脚本,使其能够自己找到修电话线的UI
6.给电话线断处加上结束事件,因为有一条电话线修好后需要炸毁前面的石头
7.创建游戏物体【石头】
8.给石头添加控制脚本。
9.创建并编写事件【当修好第一个电话线】,召唤一枚炮弹砸向石头,石头检测到炮弹后销毁自己和炮弹,并在原地生成一个投掷物堆。
10.给炮弹加上标识,不是特殊的炮弹砸不烂石头。
下班,就剩9天了……😔
100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEditor;
|
|
|
|
public class TelephoneLine : Interactive
|
|
{
|
|
//电话线类,控制每一处断裂的电话线
|
|
// Start is called before the first frame update
|
|
private float allNeedTime;
|
|
private float hasReparedTime = 0f;
|
|
private bool isReparing = false;
|
|
[SerializeField][ReadOnly]
|
|
private bool isRepared = false;
|
|
IndexRecoder indexRecoder;
|
|
private float process = 0f;
|
|
[Tooltip("特殊电话线用,拖入这个电话线修好后的事件")]
|
|
public Event endEvent;
|
|
|
|
void Start()
|
|
{
|
|
indexRecoder = FindObjectOfType<IndexRecoder>();
|
|
allNeedTime = indexRecoder.TelephoneNeedTime;
|
|
m_interface = GameObject.Find("Canvas").transform.Find("修电话线界面").gameObject;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if(!isRepared&&isReparing)//如果没有修复并且正在修复
|
|
{
|
|
//在修复的话,每帧累计时间,并更新进度
|
|
hasReparedTime += Time.deltaTime;
|
|
process = hasReparedTime/allNeedTime;
|
|
//检查是否满了
|
|
if(process >= 1f)
|
|
{
|
|
isRepared = true;//标记自己已经被修好
|
|
FindObjectOfType<AllLinesInfo>().OKCount++;//找到总线信息,给好了的电话线+1
|
|
Debug.Log("满了,这个修好了");
|
|
OnStopReparing();//关下UI
|
|
if(endEvent != null) endEvent.OnCall();//如果有结束事件,那触发一下结束事件
|
|
}
|
|
//还要更新UI上的进度条
|
|
for(int i = 0; i < m_interface.transform.childCount; i++)
|
|
if(m_interface.transform.GetChild(i).tag == "进度条")
|
|
m_interface.transform.GetChild(i).GetComponent<Image>().fillAmount = process;
|
|
}
|
|
}
|
|
|
|
public override void OnCall()
|
|
{
|
|
//象征着按下交互键了,如果这个还没被修好,即刻开始修复电话线
|
|
if(!isRepared)
|
|
{
|
|
m_interface.SetActive(true);
|
|
StartRepareTheTelephoneLine();
|
|
}
|
|
}
|
|
|
|
private void StartRepareTheTelephoneLine()
|
|
{
|
|
isReparing = true;
|
|
}
|
|
|
|
public override void StopRepareTheTelephoneLine()
|
|
{
|
|
isReparing = false;
|
|
OnStopReparing();
|
|
}
|
|
|
|
//当此电话线修好了
|
|
private void OnStopReparing()
|
|
{
|
|
m_interface.SetActive(false);//关闭修电话线的UI
|
|
}
|
|
|
|
|
|
|
|
//制造一个只读的变量,不要动这些
|
|
public class ReadOnlyAttribute : PropertyAttribute{}
|
|
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
|
public class ReadOnlyDrawer : PropertyDrawer
|
|
{
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
{
|
|
return EditorGUI.GetPropertyHeight(property, label, true);
|
|
}
|
|
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
GUI.enabled = false;
|
|
EditorGUI.PropertyField(position, property, label, true);
|
|
GUI.enabled = true;
|
|
}
|
|
}
|
|
//
|
|
}
|