我有一辆车,四个3D文本加速,制动,左和右。都有箱式对撞机。我已将以下脚本附加到主摄像头
using UnityEngine;
using System.Collections;
public class GamePlayCamera : MonoBehaviour {
void FixedUpdate ()
{
if ( Application.platform == RuntimePlatform.IPhonePlayer ||
Application.platform == RuntimePlatform.Android )
{
if ( Input.touchCount <= 0 )
return;
for(int i = 0 ; i<Input.touches.Length; i++)
{
Touch touch = Input.touches[i];
if ( touch.phase == TouchPhase.Began )
{
OnTouchBegan( touch.position );
}
else if(touch.phase == TouchPhase.Ended)
{
OnTouchEnd( touch.position );
}
}
}
else
{
if ( Input.GetMouseButtonDown( 0 ) )
{
Debug.Log(Input.mousePosition);
OnTouchBegan( Input.mousePosition );
}
else if(Input.GetMouseButtonUp(0))
{
OnTouchEnd( Input.mousePosition );
}
}
}
void OnTouchBegan (Vector2 screenPos)
{
Ray ray = Camera.main.ScreenPointToRay( screenPos );
RaycastHit hit;
if ( Physics.Raycast( ray, out hit ) )
{
if(hit.collider.gameObject.name.Equals("Acc"))
{
hit.collider.gameObject.SendMessage("Accel", SendMessageOptions.DontRequireReceiver);
}
else if(hit.collider.gameObject.name.Equals("brk"))
{
hit.collider.gameObject.SendMessage("TouchDown", SendMessageOptions.DontRequireReceiver);
}
else if(hit.collider.gameObject.name.Equals("LFT"))
{
hit.collider.gameObject.SendMessage("TouchDown", SendMessageOptions.DontRequireReceiver);
}
else if(hit.collider.gameObject.name.Equals("RHT"))
{
hit.collider.gameObject.SendMessage("TouchDown", SendMessageOptions.DontRequireReceiver);
}
}
}
void OnTouchEnd (Vector2 screenPos)
{
Ray ray = Camera.main.ScreenPointToRay( screenPos );
RaycastHit hit;
if ( Physics.Raycast( ray, out hit ) )
{
if(hit.collider.gameObject.name.Equals("Acc"))
{
hit.collider.gameObject.SendMessage("DAccel", SendMessageOptions.DontRequireReceiver);
}
else if(hit.collider.gameObject.name.Equals("brk"))
{
hit.collider.gameObject.SendMessage("TouchUp", SendMessageOptions.DontRequireReceiver);
}
else if(hit.collider.gameObject.name.Equals("LFT"))
{
hit.collider.gameObject.SendMessage("TouchUp", SendMessageOptions.DontRequireReceiver);
}
else if(hit.collider.gameObject.name.Equals("RHT"))
{
hit.collider.gameObject.SendMessage("TouchUp", SendMessageOptions.DontRequireReceiver);
}
}
}
}
汽车运动的逻辑很好我用鼠标多次测试了它。 问题是多点触控不能正常工作。第一次使用MultiTouch但是在点击按钮几次后它开始表现得很奇怪。当我点击左键时,Accelerate的功能开始工作,有些时候没有任何反应。任何人都可以告诉我这是什么问题吗?我是Unity的新手,遇到了一些问题。请帮忙。 感谢。