Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
How to make difference between click with moving with click without moving gameobject in unity

I have 2 2D gameobjects in unity.I want to achieve next but only with Input.GetTouch for android:

  1. When i click on first or second object---play some sound.
  2. When drag any of those game objets to each other combine them to one---without playing sound from first case.
  3. Then be able to click on this combined object---without playing sound from first case

Problem is because I dont want to play sound from first case if object is dragging. I already tried some code with couroutine but it doesnt work:

   if (Input.touchCount > 0) {
     touch = Input.GetTouch(0);
     touchPos = Camera.main.ScreenToWorldPoint(touch.position);
     RaycastHit2D hit = Physics2D.Raycast(touchPos, Camera.main.transform.forward);

     switch (touch.phase) {

     case TouchPhase.Began:
       samoKlik = true;
       if (samoKlik) {
         StartCoroutine(korotinaKlika());
       }
     }
     case TouchPhase.Moved:
       isMoved = true;

     if (!samoKlik) {
       if (jedan) {

         break;

         case TouchPhase.Ended:
           isMoved = false;
         jedan = false;

         break;
       }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to write your switch case properly. This code will not compile. The proper switch case syntac would be somethink like the one described here:

        switch (touch.phase) {
            case TouchPhase.Began:
                samoKlik = true;
                //if (samoKlik) { // This is not needed
                   StartCoroutine(korotinaKlika());
                //}
               break;
            case TouchPhase.Moved:
                isMoved = true;
                if (!samoKlik) { // samoKlik does not exist here
                    if (jedan) {
                       break;
                    }
                }
                break;
            case TouchPhase.Ended:
               isMoved = false;
               jedan = false;
               break;
       }

Since you want to fall from one conditional to another, it looks like the switch statement is not right for you.

I would suggest to try the following:

  1. Declare your variables before your logic
bool samoKlik = false;
bool isMoved = false;
bool jedan = false;
  1. Start with if/else clauses.

I can identify one for you to help you going

if (touch.phase == touchPhase.Moved && !samoKlik && jedan)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!