【发布时间】:2016-07-07 05:56:57
【问题描述】:
在寻找解决方案后,我仍然无法弄清楚为什么我的统一多点触控脚本不起作用。这是我的代码。在你问之前:所有变量都存在。
void Update()
{
if (Input.touchCount > 0)
{
for (i = 0; i < Input.touchCount; i++)
{
if (Input.GetTouch(i).phase != TouchPhase.Ended)
{
hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);
if (hit.collider != null && hit.transform.gameObject.tag == "Links")
{
cannon.GetComponent<Rigidbody2D>().MovePosition(cannon.GetComponent<Rigidbody2D>().position + new Vector2(-0.1f, 0) * Time.deltaTime * moveSpeed);
}
else if (hit.collider != null && hit.transform.gameObject.tag == "Rechts")
{
cannon.GetComponent<Rigidbody2D>().MovePosition(cannon.GetComponent<Rigidbody2D>().position + new Vector2(0.1f, 0) * Time.deltaTime * moveSpeed);
}
}
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);
if (hit.collider != null && hit.transform.gameObject.tag == "Fire")
{
clone = Instantiate(projectile, cannon.transform.position + new Vector3(0, 1.3f, 0), transform.rotation) as Rigidbody2D;
clone.velocity = new Vector2(0, speed);
}
}
}
}
}
它一次只注册一个输入。是的,我的手机确实支持多点触控。我将不胜感激。
【问题讨论】:
-
只需添加 Debug.Log 行即可调试您的代码。 ...你会很快找到问题
标签: android unity3d touch multi-touch