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 /
avatar image
0
Question by educa_games · Feb 18, 2021 at 02:31 PM · score systemclosed

Script for score point counting points when it shouldnt

Hi, Im new at unity and C# and english isnt my first language, so I hope its understandable.


So, Im making a game in which the player will drag and drop cards in their respective places. When he doesnt put the card in the right place, it goes back to its initial position. If he drop the card near its right place, it snaps into its slot. I put a script for when the player drops the card at the right place, he earns 10 or 20 points. The problem is, after the player drops the first card into place, the score counter adds 10 every time he drops a card, even if its not in its right place.


I created a script "Manager" that i added to the objetic "Level manager" for the drag and drop, and put an "if" statement, like, if "nameCorrect" adds 10 points. "Pontos" is responsable for the "if" that adds the points, "name of object Place" are the slots. I used event trigger because of one of the many videos i watched, but i dont know if its the best solution.


Manager code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Manager : MonoBehaviour
 {
     public GameObject titulo, publico, tempo, bse, objetivo, atividades, confirmativo, avaliacao, corretivo, tituloPlace, publicoPlace, tempoPlace, bsePlace, objetivoPlace, atividadesPlace, confirmativoPlace, avaliacaoPlace, corretivoPlace;
     Vector2 tituloInitialPos, publicoInitialPos, tempoInitialPos, bseInitialPos, objetivoInitialPos, atividadesInitialPos, confirmativoInitialPos, avaliacaoInitialPos, corretivoInitialPos;
     public AudioSource source;
     public AudioClip correct;
 
     bool tituloCorrect, publicoCorrect, tempoCorrect, bseCorrect, objetivoCorrect, atividadesCorrect, confirmativoCorrect, avaliacaoCorrect, corretivoCorrect = false;
     
     void Start()
     {
         tituloInitialPos = titulo.transform.position;
         publicoInitialPos = publico.transform.position;
         tempoInitialPos = tempo.transform.position;
         bseInitialPos = bse.transform.position;
         objetivoInitialPos = objetivo.transform.position;
         atividadesInitialPos = atividades.transform.position;
         confirmativoInitialPos = confirmativo.transform.position;
         avaliacaoInitialPos = avaliacao.transform.position;
         corretivoInitialPos = corretivo.transform.position;
     }
 
     ///PUXAR O CARD
     public void DragTitulo()
     {        titulo.transform.position = Input.mousePosition;    }
 
     public void DragPublico()
     {        publico.transform.position = Input.mousePosition;    }
         public void DragTempo()
     {        tempo.transform.position = Input.mousePosition;    }
     public void DragBse()
     {        bse.transform.position = Input.mousePosition;    }
     public void DragObjetivo()
     {        objetivo.transform.position = Input.mousePosition;    }
     public void DragAtividades()
     {        atividades.transform.position = Input.mousePosition;    }
     public void DragConfirmativo()
     {        confirmativo.transform.position = Input.mousePosition;    }
     public void DragAvaliacao()
     {        avaliacao.transform.position = Input.mousePosition;    }
     public void DragCorretivo()
     {        corretivo.transform.position = Input.mousePosition;    }
     //-------------------------------------------------------------------------------------------------------
 
     //SOLTAR O CARD
     public void DropTitulo()
     {
         float Distance = Vector3.Distance(titulo.transform.position, tituloPlace.transform.position);
         if (Distance < 50)
         {
             titulo.transform.position = tituloPlace.transform.position;
             source.clip = correct;
             source.Play();
             tituloCorrect = true;
 
         }
         else
         {
             titulo.transform.position = tituloInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
 
     public void DropPublico()
     {
         float Distance = Vector3.Distance(publico.transform.position, publicoPlace.transform.position);
         if (Distance < 50)
         {
             publico.transform.position = publicoPlace.transform.position;
             source.clip = correct;
             source.Play();
             publicoCorrect = true;
         }
         else
         {
             publico.transform.position = publicoInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
     public void DropTempo()
     {
         float Distance = Vector3.Distance(tempo.transform.position, tempoPlace.transform.position);
         if (Distance < 50)
         {
             tempo.transform.position = tempoPlace.transform.position;
             source.clip = correct;
             source.Play();
             tempoCorrect = true;
         }
         else
         {
             tempo.transform.position = tempoInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
 
     public void DropBse()
     {
         float Distance = Vector3.Distance(bse.transform.position, bsePlace.transform.position);
         if (Distance < 50)
         {
             bse.transform.position = bsePlace.transform.position;
             source.clip = correct;
             source.Play();
             bseCorrect = true;
         }
         else
         {
             bse.transform.position = bseInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
 
     public void DropObjetivo()
     {
         float Distance = Vector3.Distance(objetivo.transform.position, objetivoPlace.transform.position);
         if (Distance < 50)
         {
             objetivo.transform.position = objetivoPlace.transform.position;
             source.clip = correct;
             source.Play();
             objetivoCorrect = true;
         }
         else
         {
             objetivo.transform.position = objetivoInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
     public void DropAtividades()
     {
         float Distance = Vector3.Distance(atividades.transform.position, atividadesPlace.transform.position);
         if (Distance < 50)
         {
             atividades.transform.position = atividadesPlace.transform.position;
             source.clip = correct;
             source.Play();
             atividadesCorrect = true;
         }
         else
         {
             atividades.transform.position = atividadesInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
     public void DropConfirmativo()
     {
         float Distance = Vector3.Distance(confirmativo.transform.position, confirmativoPlace.transform.position);
         if (Distance < 50)
         {
             confirmativo.transform.position = confirmativoPlace.transform.position;
             source.clip = correct;
             source.Play();
             confirmativoCorrect = true;
         }
         else
         {
             confirmativo.transform.position = confirmativoInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
     public void DropAvaliacao()
     {
         float Distance = Vector3.Distance(avaliacao.transform.position, avaliacaoPlace.transform.position);
         if (Distance < 50)
         {
             avaliacao.transform.position = avaliacaoPlace.transform.position;
             source.clip = correct;
             source.Play();
             avaliacaoCorrect = true;
         }
         else
         {
             avaliacao.transform.position = avaliacaoInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
     public void DropCorretivo()
     {
         float Distance = Vector3.Distance(corretivo.transform.position, corretivoPlace.transform.position);
         if (Distance < 50)
         {
             corretivo.transform.position = corretivoPlace.transform.position;
             source.clip = correct;
             source.Play();
             corretivoCorrect = true;
         }
         else
         {
             corretivo.transform.position = corretivoInitialPos;
             source.clip = correct;
             source.Play();
         }
     }
 
     public void Pontos()
     {
         if (tituloCorrect)
         {            
             ScoreScript.scoreValue = 10;
         }
 
         if (publicoCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
 
         if (tempoCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
 
         if (bseCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
         if (objetivoCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
 
         if (atividadesCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
         if (confirmativoCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
 
         if (avaliacaoCorrect)
         {            
             ScoreScript.scoreValue += 20;
         }
         if (corretivoCorrect)
         {            
             ScoreScript.scoreValue += 10;
         }
 
         
     }
 
     
 }
 
 

Score Points code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class ScoreScript : MonoBehaviour
 {
     private int nextSceneToLoad;
     public static int scoreValue = 0;
     Text score;
 
     void Start()
     {
         score = GetComponent<Text>();
         nextSceneToLoad = SceneManager.GetActiveScene().buildIndex + 1;
 
     }
 
     public void selectScene()
     {
         switch (this.gameObject.name)
         {
             case "NextScene":
                 SceneManager.LoadScene(nextSceneToLoad);
                 break;
         }
     }
 
                 // Update is called once per frame
                 void Update()
     {
         score.text = "" + scoreValue;
         if (scoreValue >= 100)
         {
             SceneManager.LoadScene("Scene02");
         }
     }
 }
 


[1]: https://ibb.co/6H9CTb6

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Megaboy238 · Feb 09, 2021 at 09:11 PM

Think its your not resetting the Correct variables

 public void Pontos()
     {
         if (tituloCorrect)
         {
             ScoreScript.scoreValue = 10;
             tituloCorrect = false;
         }
 
         if (publicoCorrect)
         {
             ScoreScript.scoreValue += 10;
             publicoCorrect = false;
         }
 
         if (tempoCorrect)
         {
             ScoreScript.scoreValue += 10;
             tempoCorrect = false;
         }
 
         if (bseCorrect)
         {
             ScoreScript.scoreValue += 10;
             bseCorrect = false;
         }
         if (objetivoCorrect)
         {
             ScoreScript.scoreValue += 10;
             objetivoCorrect = false;
         }
 
         if (atividadesCorrect)
         {
             ScoreScript.scoreValue += 10;
             atividadesCorrect = false;
         }
         if (confirmativoCorrect)
         {
             ScoreScript.scoreValue += 10;
             confirmativoCorrect = false;
         }
 
         if (avaliacaoCorrect)
         {
             ScoreScript.scoreValue += 20;
             avaliacaoCorrect = false;
         }
         if (corretivoCorrect)
         {
             ScoreScript.scoreValue += 10;
             corretivoCorrect = false;
         }
 
 
     }
Comment
Add comment · Share
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
avatar image
0

Answer by educa_games · Feb 11, 2021 at 11:08 AM

It worked, thank you!

Comment
Add comment · Show 1 · Share
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
avatar image GDGames0302 · Feb 13, 2021 at 07:52 PM 0
Share

Hi. If you found the correct answer, please mark this question as Closed(from the edit button). Thank you.

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

111 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

Related Questions

[closed] What are the names of the buttons on a wii remote? 1 Answer

How to add playerPrefs to this script? 1 Answer

How to set the High Score to be the Final Score? 1 Answer

How to alter c# script from a script in a different scene (i.e. display score in different scene) 2 Answers

How can I use particles of several partical systems for a score? 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