Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 11, 2021 at 05:09 PM · drag and drop

How do I deactivate the drag and drop after the Panel is dropped in its right place?

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. I put a script for when the player drops the card at the right place, he earns 10 points. When it reaches 100, it goes to the next scene. The problem is, the player can just keep putting the same card into the same place, and the counter keeps going. How do i block the card after it is in its right place?


Im using Event Trigger for the drag, drop and the score. The object being dragged is a Panel.


Manager

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Manager : MonoBehaviour
 {
     public GameObject titulo, publico, tituloPlace, publicoPlace;
     Vector2 tituloInitialPos, publicoInitialPos;
     public AudioSource source;
     public AudioClip correct;
 
     bool tituloCorrect, publicoCorrect = false;
     
     void Start()
     {
         tituloInitialPos = titulo.transform.position;
         publicoInitialPos = publico.transform.position;
         }
 
    public void DragTitulo()
     {        titulo.transform.position = Input.mousePosition;    }
 
     public void DragPublico()
     {        publico.transform.position = Input.mousePosition;    }
     //---------------------------------------------------------
 
    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 Pontos()
     {
         if (tituloCorrect)
         {            
             ScoreScript.scoreValue += 10;
             tituloCorrect = false;
         }
 
         if (publicoCorrect)
         {            
             ScoreScript.scoreValue += 10;
             publicoCorrect = false;
         } }}       
   



Score script (if needed)

 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");
         }}}

Im new at C# and unity, so i hope im being clear.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zymurer · Feb 13, 2021 at 09:49 PM

Why you cannot use if clause?

 public void DragTitulo()
      {
         if(tituloCorrect == false){
 ``titulo.transform.position = Input.mousePosition; 
 }

What happens when you use it?

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 educa_games · Feb 18, 2021 at 12:27 PM 0
Share

Im new at c#, I'm not sure how to use it. I tried that, but it just doesn't move

public void DragTitulo() { if (tituloCorrect == false) {titulo.transform.position = Input.mousePosition; } }`

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

110 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

Related Questions

Error in raycast using with drag drop of objects 0 Answers

Can no longer drag in images/sprites into and within my project folder 2 Answers

How to drag and drop an UI Image on a 2D GameObject? 0 Answers

Matching objects using drag and drop 1 Answer

onMaterialChange or SceneView.onDropMaterial 1 Answer


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