Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by alphaemu · Nov 02, 2020 at 10:03 AM · variablerhythmmultiply

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;
 
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

215 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make sure an object is at a certain position when a float has a certain value? 0 Answers

Use enum hidden value as something other than int? (C#) 2 Answers

Adding to variable only once? 0 Answers

Logical explaination of this code 1 Answer

name a variable when it's created??? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges