【发布时间】:2016-04-05 16:33:36
【问题描述】:
当我将手机用作测试设备时,我的 OnTriggerEnter 有点问题。 我有一些触摸代码可以成功地让我在屏幕上拖动对象。 然后我让这些对象与屏幕上的其他对象发生碰撞。
在我将对象变成预制件之前,这一切都很好。 (我需要这样做,因为对象是在运行时随机生成的)
现在,我仍然可以在屏幕上移动对象,但它们不再与其他对象发生碰撞,这些对象也是预制件。但是,在我的笔记本电脑上的统一编辑器中运行它时,它仍然可以正常工作。
我所有的物体上都有碰撞体,触发检查,移动物体有刚体。
触发输入代码
public void OnTriggerEnter(Collider other)
{
Debug.Log ("here");
Debug.Log(this.gameObject.tag +"is this");
Debug.Log(other.gameObject.tag + "is other");
if (this.gameObject.tag == other.gameObject.tag)
{
Debug.Log("here2)");
Reftomanager.miniGameScore++;
Reftomanager.updateScore();
Destroy(this.gameObject);
}
}
触摸码
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
switch(touch.phase)
{
case TouchPhase.Began:
Ray ray = Camera.main.ScreenPointToRay (touch.position);
if (Physics.Raycast(ray,out hit))
{
thisObject = hit.collider.gameObject;
touchPos = Camera.main.ScreenToWorldPoint (touch.position);
if(thisObject.name!="circle")
{
draggingMode = true;
}
}
break;
case TouchPhase.Moved:
if (draggingMode)
{
touchPos = Camera.main.ScreenToWorldPoint (touch.position);
newCentre = touchPos;
thisObject.transform.position = touchPos;
}
break;
case TouchPhase.Ended:
draggingMode = false;
break;
}
}
}
我完全被难住了,所以任何帮助都会很棒。
谢谢
【问题讨论】:
标签: android unity3d touch collision-detection