
1.创建可交互电报机这个逻辑物体 *.在所有脚本首行添加说明方便查看 2.编写假电报机类,因为这个电报机没有电报机功能,而是一个类似事件的物体。 3.使假电报机可以分清场景中电话线断裂和修复的情况,并对其做出不同反应。 4.没修完电报机的反馈等待策划,修完了的等待我明天编写场景的多态系统 5.均通过了程序简单测试,请各位尽快拉取寻找问题 下班,别摸了,兄弟们
72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TelephoneLine : Interactive
|
|
{
|
|
//电话线类,控制每一处断裂的电话线
|
|
// Start is called before the first frame update
|
|
private float allNeedTime;
|
|
private float hasReparedTime = 0f;
|
|
private bool isReparing = false;
|
|
public bool isRepared = false;
|
|
IndexRecoder indexRecoder;
|
|
private float process = 0f;
|
|
|
|
void Start()
|
|
{
|
|
indexRecoder = FindObjectOfType<IndexRecoder>();
|
|
allNeedTime = indexRecoder.TelephoneNeedTime;
|
|
}
|
|
|
|
// 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++;
|
|
Debug.Log("满了,这个修好了");
|
|
OnStopReparing();
|
|
}
|
|
//还要更新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);
|
|
}
|
|
}
|