4
我使用OnMouseDown()
來處理按壓,但不可能實現多點觸控。如何在移動設備上的Unity3d中實現多點觸控?
該程序包含在您點擊然後減少時會增加的對象。如果只有一次觸摸,一切正常。但是,當您嘗試同時點擊幾個對象時,它不起作用。
我正試圖解決這個問題,但它不工作,對象不能縮放和多點觸摸不起作用。
代碼:
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);}
}
}