I use OnMouseDown()
可以处理按压,但不可能实现多点触控。
该程序包括当您点击时增加然后减少的对象。如果轻轻一按,一切都会正常。但是,当您尝试同时单击多个对象时,它不起作用。
我正在尝试解决该问题,但它不起作用,对象无法缩放并且多点触控不起作用。
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);}
}
}
您确实不应该将鼠标事件用于触摸设备。 Unity 为您提供了将第一次触摸映射到鼠标事件的便利,但仅此而已。
Unity对触摸设备的支持:
Touch http://docs.unity3d.com/ScriptReference/Touch.html
输入.GetTouch http://docs.unity3d.com/ScriptReference/Input.GetTouch.html
官方视频教程 https://unity3d.com/learn/tutorials/modules/beginner/platform-specific/multitouch-input
为了在您的解决方案中支持多个平台(PC、平板电脑、手机等),您应该研究:
平台相关编译 http://docs.unity3d.com/Manual/PlatformDependentCompilation.html
输入.GetTouch代码示例
public class TouchTest : MonoBehaviour
{
void Update ()
{
Touch myTouch = Input.GetTouch(0);
Touch[] myTouches = Input.touches;
for(int i = 0; i < Input.touchCount; i++)
{
//Do something with the touches
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)