Need Distance-Based Score Multiplier For Multiple Assets (Typing Rhythm Game)
So, I'm a college student majoring in game design that's been messing around in Unity for the past few days and while I have a good amount of standard Java experience, I'm stranded in C# and how exactly to access certain things, etc. etc. What I'm trying to make is a rhythm typing game, where as the letters get closer to an on-screen keyboard your point total increases as a song plays in the background. After hours of work, I was able to get a distanceMultiplier to work, but I can't access it. I've tried many things. I've searched the forums, scanned Google, and every answer is either more complicated than I can understand or does not solve my particular issue. I've attached the code for the two scripts that apply here: my GameManager, and my DistanceMeasure. I have a DistanceMeasure script applied to every letter PreFab that falls down on the screen, and the only work-around I've found to at least get the GameManager to recognize the DistanceMultiplier only allows me to measure a single letter's distance. Sorry if any of my explanation is confusing, I've been troubleshooting this logic error for 4 hours now and have finally given up, so any help is appreciated at this point. Thanks for reading!
public class GameManager : MonoBehaviour
{
public AudioSource music;
public bool startPlaying;
public BeatScroller theBS;
public DistanceMeasure theDM;
public static GameManager instance;
public int currentScore;
public int scorePerNote;
public Text scoreText;
public int currentMultiply;
public int streak;
public int[] multiplier;
// Start is called before the first frame update
void Start()
{
instance = this;
scoreText.text = "0";
currentMultiply = 1;
streak = 0;
}
// Update is called once per frame
void Update()
{
if (!startPlaying)
{
if (Input.anyKeyDown)
{
startPlaying = true;
theBS.hasStarted = true;
music.Play();
}
}
}
public void NoteHit()
{
int distanceMultiply = theDM.distanceMultiplier;
Debug.Log("Hit");
if (currentMultiply - 1 < multiplier.Length)
{
streak++;
if (multiplier[currentMultiply - 1] <= streak)
{
streak = 0;
currentMultiply++;
}
}
currentScore += scorePerNote * currentMultiply * distanceMultiply;
scoreText.text = currentScore.ToString();
}
public void NoteMiss()
{
Debug.Log("Missed");
streak = 0;
currentMultiply = 1;
}
}
public class DistanceMeasure : MonoBehaviour
{
public GameObject key;
public GameObject letter;
public float distanceBetween;
public int distanceMultiplier;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
distanceBetween = Vector3.Distance(key.transform.position, letter.transform.position);
distanceBetween = Mathf.Abs(Mathf.Ceil(distanceBetween));
switch (distanceBetween)
{
case 20:
distanceMultiplier = 1;
break;
case 19:
distanceMultiplier = 2;
break;
case 18:
distanceMultiplier = 3;
break;
case 17:
distanceMultiplier = 4;
break;
case 16:
distanceMultiplier = 5;
break;
case 15:
distanceMultiplier = 6;
break;
case 14:
distanceMultiplier = 7;
break;
case 13:
distanceMultiplier = 8;
break;
case 12:
distanceMultiplier = 9;
break;
case 11:
distanceMultiplier = 10;
break;
case 10:
distanceMultiplier = 11;
break;
case 9:
distanceMultiplier = 12;
break;
case 8:
distanceMultiplier = 13;
break;
case 7:
distanceMultiplier = 14;
break;
case 6:
distanceMultiplier = 15;
break;
case 5:
distanceMultiplier = 16;
break;
case 4:
distanceMultiplier = 17;
break;
case 3:
distanceMultiplier = 18;
break;
case 2:
distanceMultiplier = 19;
break;
case 1:
distanceMultiplier = 20;
break;
case 0:
distanceMultiplier = 25;
break;
default:
distanceMultiplier = 1;
break;
}
}
}