c# – 如何在移动设备上的Unity3d中实现多点触控?

c# – 如何在移动设备上的Unity3d中实现多点触控?,第1张

概述我使用OnMouseDown()来处理按压,但是不可能实现多点触控.该程序包括在您点击然后减少时增加的对象.如果只有一次触摸,一切正常.但是,当您尝试同时单击多个对象时,它无法正常工作.我正在尝试解决问题,但它无法正常工作,对象无法扩展,多点触控不起作用.码:usingUnityEngine;usi

我使用OnMouseDown()来处理按压,但是不可能实现多点触控.

该程序包括在您点击然后减少时增加的对象.如果只有一次触摸,一切正常.但是,当您尝试同时单击多个对象时,它无法正常工作.

我正在尝试解决问题,但它无法正常工作,对象无法扩展,多点触控不起作用.

码:

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 onm ouseDown(){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设备的支持:
Touch
Input.GetTouch
Official Video Tutorial

为了在您的解决方案中支持多个平台(PC,平板电脑,手机等),您应该考虑:
Platform Dependent Compilation

input.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        }    }}
总结

以上是内存溢出为你收集整理的c# – 如何在移动设备上的Unity3d中实现多点触控?全部内容,希望文章能够帮你解决c# – 如何在移动设备上的Unity3d中实现多点触控?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1118124.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存