Unity Rythm游戏的失败机制
您好,我知道这个问题可能是一个糟糕的问题,但是我已经尝试了所有能力来解决这个问题,但我不能,所以我一直在制作一场Rythm游戏,而我的一生,除了失败的机制外,我还做了其他所有事情只是无法让它工作。我需要读取变量(错过),并使代码暂停时间并显示文字说(错过的笔记太多)。我已经把文本插入其中的地方,但我无法弄清楚如何做。我是一个居民,所以任何帮助都很好,感谢您的帮助。
这是代码
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public AudioSource theMusic;
public AudioSource beatSfx;
public bool startPlaying;
public BeatScroller theBS;
public static GameManager instance;
public int currentScore;
public int scorePerNote = 2000;
public int scorePerGoodNote = 2500;
public int scorePerPerfectNote = 3000;
public int currentMultiplier;
public int multiplierTracker;
public int[] multiplierThresholds;
public Text scoreText;
public Text multiText;
public float totalNotes;
public float NormalHits;
public float GoodHits;
public float PerfectHits;
public float MissedHits;
public GameObject resultsScreen;
public Text percentHitText, normalsText, goodsText, perfectsText, missesText, rankText, finalScoreText;
public GameObject FAILTEXT;
// Start is called before the first frame update
void Start()
{
instance = this;
scoreText.text = "Press Any Key to Continue";
currentMultiplier = 1;
totalNotes = ((FindObjectsOfType<NoteObject>().Length) - 168);
}
// Update is called once per frame
void Update()
{
if (!startPlaying)
{
if (Input.anyKeyDown)
{
scoreText.text = "0";
startPlaying = true;
theBS.hasStarted = true;
theMusic.Play();
}
}
else
{
if (!theMusic.isPlaying && !resultsScreen.activeInHierarchy)
{
resultsScreen.SetActive(true);
normalsText.text = "" + NormalHits;
goodsText.text = "" + GoodHits;
perfectsText.text = "" + PerfectHits;
missesText.text = "" + MissedHits;
float totalHits = NormalHits + GoodHits + PerfectHits;
float percentHit = (totalHits / totalNotes) * 100f;
float totalMiss = MissedHits;
percentHitText.text = percentHit.ToString("F1") + "%";
string rankVal = "F";
if (percentHit >= 30)
{
rankVal = "D";
if (currentScore >= 550000)
{
rankVal = "C";
if (currentScore >= 750000)
{
rankVal = "B";
if (currentScore >= 900000)
{
rankVal = "A";
if (currentScore >= 950000)
{
rankVal = "S";
}
}
}
}
}
rankText.text = rankVal;
finalScoreText.text = currentScore.ToString();
}
}
}
public void NoteHit()
{
beatSfx.Play();
multiplierTracker++;
if ((currentMultiplier - 1) < multiplierThresholds.Length)
{
multiplierTracker++;
if (multiplierThresholds[currentMultiplier - 1] <= multiplierTracker)
{
multiplierTracker = 0;
currentMultiplier++;
}
}
scoreText.text = "" + currentScore;
multiText.text = "Score x" + currentMultiplier;
}
public void NormalHit()
{
UnityEngine.Debug.Log("Normal Hit");
currentScore += scorePerNote * currentMultiplier;
NormalHits++;
NoteHit();
}
public void GoodHit()
{
UnityEngine.Debug.Log("Good Hit");
currentScore += scorePerGoodNote * currentMultiplier;
GoodHits++;
NoteHit();
}
public void PerfectHit()
{
UnityEngine.Debug.Log("Perfect Hit");
currentScore += scorePerPerfectNote * currentMultiplier;
PerfectHits++;
NoteHit();
}
public void NoteMissed()
{
UnityEngine.Debug.Log("missed");
MissedHits++;
currentMultiplier = 1;
multiplierTracker = 0;
multiText.text = "Score x" + currentMultiplier;
}
}
Hello i know this question might be a bad one but i have tried everything to my ability to acomplish this but i cant, so i have been making a rythm game and for the life of me i have made everything else other than the fail mechanism i just cant get it to work. i need to read the variable (MissedNotes) and make the code pause the time and show text saying (Too Many Notes Missed). I have made the place to insert the text in but i cant figure out how to do it at all. Im a begginer so any help is good, Thanks for helping me.
This is the code
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public AudioSource theMusic;
public AudioSource beatSfx;
public bool startPlaying;
public BeatScroller theBS;
public static GameManager instance;
public int currentScore;
public int scorePerNote = 2000;
public int scorePerGoodNote = 2500;
public int scorePerPerfectNote = 3000;
public int currentMultiplier;
public int multiplierTracker;
public int[] multiplierThresholds;
public Text scoreText;
public Text multiText;
public float totalNotes;
public float NormalHits;
public float GoodHits;
public float PerfectHits;
public float MissedHits;
public GameObject resultsScreen;
public Text percentHitText, normalsText, goodsText, perfectsText, missesText, rankText, finalScoreText;
public GameObject FAILTEXT;
// Start is called before the first frame update
void Start()
{
instance = this;
scoreText.text = "Press Any Key to Continue";
currentMultiplier = 1;
totalNotes = ((FindObjectsOfType<NoteObject>().Length) - 168);
}
// Update is called once per frame
void Update()
{
if (!startPlaying)
{
if (Input.anyKeyDown)
{
scoreText.text = "0";
startPlaying = true;
theBS.hasStarted = true;
theMusic.Play();
}
}
else
{
if (!theMusic.isPlaying && !resultsScreen.activeInHierarchy)
{
resultsScreen.SetActive(true);
normalsText.text = "" + NormalHits;
goodsText.text = "" + GoodHits;
perfectsText.text = "" + PerfectHits;
missesText.text = "" + MissedHits;
float totalHits = NormalHits + GoodHits + PerfectHits;
float percentHit = (totalHits / totalNotes) * 100f;
float totalMiss = MissedHits;
percentHitText.text = percentHit.ToString("F1") + "%";
string rankVal = "F";
if (percentHit >= 30)
{
rankVal = "D";
if (currentScore >= 550000)
{
rankVal = "C";
if (currentScore >= 750000)
{
rankVal = "B";
if (currentScore >= 900000)
{
rankVal = "A";
if (currentScore >= 950000)
{
rankVal = "S";
}
}
}
}
}
rankText.text = rankVal;
finalScoreText.text = currentScore.ToString();
}
}
}
public void NoteHit()
{
beatSfx.Play();
multiplierTracker++;
if ((currentMultiplier - 1) < multiplierThresholds.Length)
{
multiplierTracker++;
if (multiplierThresholds[currentMultiplier - 1] <= multiplierTracker)
{
multiplierTracker = 0;
currentMultiplier++;
}
}
scoreText.text = "" + currentScore;
multiText.text = "Score x" + currentMultiplier;
}
public void NormalHit()
{
UnityEngine.Debug.Log("Normal Hit");
currentScore += scorePerNote * currentMultiplier;
NormalHits++;
NoteHit();
}
public void GoodHit()
{
UnityEngine.Debug.Log("Good Hit");
currentScore += scorePerGoodNote * currentMultiplier;
GoodHits++;
NoteHit();
}
public void PerfectHit()
{
UnityEngine.Debug.Log("Perfect Hit");
currentScore += scorePerPerfectNote * currentMultiplier;
PerfectHits++;
NoteHit();
}
public void NoteMissed()
{
UnityEngine.Debug.Log("missed");
MissedHits++;
currentMultiplier = 1;
multiplierTracker = 0;
multiText.text = "Score x" + currentMultiplier;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里没有任何控制时间,因此在此课程中没有什么可做的事情可以暂停时间。我也没有看到音符命中功能是如何调用的。
似乎还有其他一些控制时间和注意点击逻辑的类,这就是您需要实现逻辑以停止游戏的地方。
完成后,您可以修改概括的方法,以触发游戏逻辑,以便在错过过多的音符时停止。
There's nothing controlling time here so there's not really anything to do in this class to pause time. I'm also not seeing how the note hit functions are called.
It seems like there's some other class controlling the timing and note hit logic, and that's where you need to implement the logic to stop the game.
Once you've done that you can modify your NoteMissed method to trigger the game logic to stop when too many notes are missed.