V
V
vladhoncharenko2015-06-15 16:30:21
Android
vladhoncharenko, 2015-06-15 16:30:21

How to implement multitouch in Unity3d on a mobile device?

I'm using OnMouseDown() to handle the click, but I can't implement multitouch in Unity3d.
The program has objects that, when pressed, increase and then decrease, if there is one touch, then everything works fine, when you try to click on several objects at once, nothing happens.
I tried to solve the problem, but it did not work, the objects stopped scaling as they should and the multitouch did not work.
The code:

using UnityEngine;
using System.Collections;

public class OnTouch : MonoBehaviour {
  public AudioClip crash1;
  public AudioClip hat_closed;
  public AudioClip hat_open;
  public bool c;
  public bool c1;
  public bool c2;
  
  void OnMouseDown(){

    if (this.name == "clash") {
      GetComponent<AudioSource>().PlayOneShot(hat_open);
      c=true;
    }
    if (this.name == "clash 1") {
      GetComponent<AudioSource>().PlayOneShot(hat_closed);
      c1=true;
    }

    if (this.name == "clash 2") {
      GetComponent<AudioSource> ().PlayOneShot (crash1);
      c2=true;
    }			
    transform.localScale += new Vector3(0.05f, 0.05f, 0);
  }

  void Update(){			
    if (c) {transform.localScale = Vector3.Lerp (this.transform.localScale, new Vector3 (0.2f, 0.2f, 0), Time.deltaTime*10f);}
    if (c1) {transform.localScale = Vector3.Lerp (this.transform.localScale, new Vector3 (0.2f, 0.2f, 0), Time.deltaTime*10f);}
    if (c2) {transform.localScale = Vector3.Lerp (this.transform.localScale, new Vector3 (0.25f, 0.25f, 0), Time.deltaTime*10f);}
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Espleth, 2015-06-15
@vladhoncharenko

Google Unity touch input.
All sorts of things for Mouse are usually not used when it comes to a wheelbarrow. On off. YouTube channel has a lot of tutorials on the subject of a wheelbarrow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question