Я разработчик Unity, и у меня возникли проблемы с созданием лучшего счетчика кругов для моей игры о гонках на лодках, над которой я работал последний год или около того. По сути, когда вы заканчиваете круг и пересекаете финишную черту, лучший таймер круга не меняется. Да, я вписал этот таймер в скрипт, но он вообще отказывается работать.
Я пробовал использовать символы < и >, но это не сработало. Я пробовал сопрограммы, но это все равно не сработало. Я даже пробовал использовать символ =, но это все равно не сработало. В конце концов я сдался и решил попросить о помощи.
Если у кого-то из вас есть решение, которое могло бы помочь решить эту проблему, не стесняйтесь публиковать его в разделе комментариев ниже, и я вам отвечу. более чем рад опробовать их и посмотреть, сработают ли они. В любом случае, хорошего дня! Ой! И вот мой код для тех, кому интересно.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Race_Manager : MonoBehaviour {
[HideInInspector]
public bool enter = false;
[HideInInspector]
public bool isCalled = true;
[HideInInspector]
public bool lapCompleted = false;
[HideInInspector]
public bool raceStarted = false;
[HideInInspector]
public float currentHour;
[HideInInspector]
public float currentMinute;
[HideInInspector]
public float currentSecond;
[HideInInspector]
public float bestHour;
[HideInInspector]
public float bestMinute;
[HideInInspector]
public float bestSecond;
public float timerSpeed = 10f;
[HideInInspector]
public int lapsDone;
public int lapsToDo = 5;
[HideInInspector]
public int pointsHit;
[HideInInspector]
public Race_Checkpoint[] checkpoints;
public Text currentTimeCounter;
public Text bestTimeCounter;
public Text lapCounter;
public Canvas normalUI;
public Canvas completionUI;
public AudioSource successMusic;
private bool raceOver = false;
private CarCameras carCamera;
private GameObject playerCar;
private bool mainFunctionCalled = false;
private bool timerActivated = false;
private bool isFirstLap = true;
// Use this for initialization
void Start () {
playerCar = GameObject.FindWithTag ("Player");
carCamera = GameObject.FindObjectOfType ();
checkpoints = GetComponentsInChildren ();
}
// Update is called once per frame
void Update () {
lapCounter.text = string.Format("Laps: {0} / {1}", lapsDone, lapsToDo);
currentTimeCounter.text = string.Format("Current Time: {0:00}:{1:00}:{2:00}", currentHour, currentMinute, currentSecond);
bestTimeCounter.text = string.Format("Best Time: {0:00}:{1:00}:{2:00}", bestHour, bestMinute, bestSecond);
if (raceOver == true && mainFunctionCalled == true) {
StartCoroutine (WinFunction());
}
if (raceOver == true) {
playerCar.GetComponent ().handbrakeInput = 1f;
}
if (timerActivated == true) {
currentSecond += Time.deltaTime * timerSpeed;
}
if (currentSecond > 60f)
{
currentSecond = 0f;
currentMinute += 1f;
}
if (currentMinute == 60f) {
currentHour += 1f;
currentMinute = 0f;
}
if (enter == true) {
foreach (Race_Checkpoint point in checkpoints)
point.ResetPoint ();
}
}
void OnTriggerEnter (Collider other)
{
if (other.transform.parent.transform.parent.transform.tag == "Player" && raceStarted == false && lapsDone == 0 && isCalled == true) {
timerActivated = true;
raceStarted = true;
lapsDone += 1;
isCalled = false;
enter = true;
} else {
enter = false;
}
if (other.transform.parent.transform.parent.transform.tag == "Player" && raceStarted == true && isCalled == true && lapCompleted) {
lapCompleted = false;
isCalled = false;
lapsDone += 1;
pointsHit = 0;
enter = true;
StartCoroutine (TimerFunction ());
} else {
enter = false;
}
if (enter == true && lapsDone == lapsToDo + 1)
{
mainFunctionCalled = true;
raceOver = true;
}
if (enter == true && lapsDone > 1f) {
StartCoroutine (TimerFunction ());
}
}
IEnumerator WinFunction() {
yield return new WaitForSeconds (0f);
RestartGame restarter = GetComponent ();
successMusic.Play ();
raceOver = true;
normalUI.gameObject.SetActive (false);
completionUI.gameObject.SetActive(true);
playerCar.GetComponent ().handbrakeInput = 1f;
playerCar.GetComponent ().throttleInput = 0f;
playerCar.GetComponent ().steerInput = 0f;
playerCar.GetComponent ().controller = CarDynamics.Controller.external;
carCamera.GetComponent ().enabled = false;
carCamera.GetComponent ().enabled = false;
carCamera.GetComponent ().Play ("Camera_Finish");
timerActivated = false;
mainFunctionCalled = false;
if (restarter != null) {
restarter.enabled = false;
}
}
IEnumerator TimerFunction()
{
yield return new WaitForSeconds (0f);
if (currentHour >= bestHour && isFirstLap && lapsDone = bestMinute && isFirstLap && lapsDone = bestSecond && isFirstLap && lapsDone
Подробнее здесь: https://stackoverflow.com/questions/783 ... ot-showing
Лучшее время круга не отображается ⇐ C#
Место общения программистов C#
1713926873
Anonymous
Я разработчик Unity, и у меня возникли проблемы с созданием лучшего счетчика кругов для моей игры о гонках на лодках, над которой я работал последний год или около того. По сути, когда вы заканчиваете круг и пересекаете финишную черту, лучший таймер круга не меняется. Да, я вписал этот таймер в скрипт, но он вообще отказывается работать.
Я пробовал использовать символы < и >, но это не сработало. Я пробовал сопрограммы, но это все равно не сработало. Я даже пробовал использовать символ =, но это все равно не сработало. В конце концов я сдался и решил попросить о помощи.
Если у кого-то из вас есть решение, которое могло бы помочь решить эту проблему, не стесняйтесь публиковать его в разделе комментариев ниже, и я вам отвечу. более чем рад опробовать их и посмотреть, сработают ли они. В любом случае, хорошего дня! Ой! И вот мой код для тех, кому интересно.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Race_Manager : MonoBehaviour {
[HideInInspector]
public bool enter = false;
[HideInInspector]
public bool isCalled = true;
[HideInInspector]
public bool lapCompleted = false;
[HideInInspector]
public bool raceStarted = false;
[HideInInspector]
public float currentHour;
[HideInInspector]
public float currentMinute;
[HideInInspector]
public float currentSecond;
[HideInInspector]
public float bestHour;
[HideInInspector]
public float bestMinute;
[HideInInspector]
public float bestSecond;
public float timerSpeed = 10f;
[HideInInspector]
public int lapsDone;
public int lapsToDo = 5;
[HideInInspector]
public int pointsHit;
[HideInInspector]
public Race_Checkpoint[] checkpoints;
public Text currentTimeCounter;
public Text bestTimeCounter;
public Text lapCounter;
public Canvas normalUI;
public Canvas completionUI;
public AudioSource successMusic;
private bool raceOver = false;
private CarCameras carCamera;
private GameObject playerCar;
private bool mainFunctionCalled = false;
private bool timerActivated = false;
private bool isFirstLap = true;
// Use this for initialization
void Start () {
playerCar = GameObject.FindWithTag ("Player");
carCamera = GameObject.FindObjectOfType ();
checkpoints = GetComponentsInChildren ();
}
// Update is called once per frame
void Update () {
lapCounter.text = string.Format("Laps: {0} / {1}", lapsDone, lapsToDo);
currentTimeCounter.text = string.Format("Current Time: {0:00}:{1:00}:{2:00}", currentHour, currentMinute, currentSecond);
bestTimeCounter.text = string.Format("Best Time: {0:00}:{1:00}:{2:00}", bestHour, bestMinute, bestSecond);
if (raceOver == true && mainFunctionCalled == true) {
StartCoroutine (WinFunction());
}
if (raceOver == true) {
playerCar.GetComponent ().handbrakeInput = 1f;
}
if (timerActivated == true) {
currentSecond += Time.deltaTime * timerSpeed;
}
if (currentSecond > 60f)
{
currentSecond = 0f;
currentMinute += 1f;
}
if (currentMinute == 60f) {
currentHour += 1f;
currentMinute = 0f;
}
if (enter == true) {
foreach (Race_Checkpoint point in checkpoints)
point.ResetPoint ();
}
}
void OnTriggerEnter (Collider other)
{
if (other.transform.parent.transform.parent.transform.tag == "Player" && raceStarted == false && lapsDone == 0 && isCalled == true) {
timerActivated = true;
raceStarted = true;
lapsDone += 1;
isCalled = false;
enter = true;
} else {
enter = false;
}
if (other.transform.parent.transform.parent.transform.tag == "Player" && raceStarted == true && isCalled == true && lapCompleted) {
lapCompleted = false;
isCalled = false;
lapsDone += 1;
pointsHit = 0;
enter = true;
StartCoroutine (TimerFunction ());
} else {
enter = false;
}
if (enter == true && lapsDone == lapsToDo + 1)
{
mainFunctionCalled = true;
raceOver = true;
}
if (enter == true && lapsDone > 1f) {
StartCoroutine (TimerFunction ());
}
}
IEnumerator WinFunction() {
yield return new WaitForSeconds (0f);
RestartGame restarter = GetComponent ();
successMusic.Play ();
raceOver = true;
normalUI.gameObject.SetActive (false);
completionUI.gameObject.SetActive(true);
playerCar.GetComponent ().handbrakeInput = 1f;
playerCar.GetComponent ().throttleInput = 0f;
playerCar.GetComponent ().steerInput = 0f;
playerCar.GetComponent ().controller = CarDynamics.Controller.external;
carCamera.GetComponent ().enabled = false;
carCamera.GetComponent ().enabled = false;
carCamera.GetComponent ().Play ("Camera_Finish");
timerActivated = false;
mainFunctionCalled = false;
if (restarter != null) {
restarter.enabled = false;
}
}
IEnumerator TimerFunction()
{
yield return new WaitForSeconds (0f);
if (currentHour >= bestHour && isFirstLap && lapsDone = bestMinute && isFirstLap && lapsDone = bestSecond && isFirstLap && lapsDone
Подробнее здесь: [url]https://stackoverflow.com/questions/78368544/best-lap-time-not-showing[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия