I use OnMouseDown()to handle clicks, but it's not possible to implement multi-touch.
The program includes objects that increase when pressed and then reduced. If there is one touch, everything works fine. But when you try to click several objects at the same time, they do not work.
I am trying to solve a problem, but it does not work, objects do not scale, and multi-touch does 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);}
}
}
source
share