ฉันกำลังพยายามลบวัตถุที่คลิกเมาส์ ฉันกำลังสร้างเกม 2D โดยใช้ Unity3D 4.3 ใหม่ นี่คือรหัสที่ฉันใช้
void Update () {
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray,out hit))
{
isHit = false;
Destroy(GameObject.Find(hit.collider.gameObject.name));
}
}
}
ตัวควบคุมไม่ได้เข้าสู่ if loop ภายใน (isHit
ไม่ได้ถูกตั้งค่าเป็นเท็จ)
Destroy(GameObject.Find(hit.collider.gameObject.name));
find ไม่จำเป็น เพียงแค่ทำDestroy(hit.collider.gameObject);
ก็ควรจะใช้ได้ดี - person Steven Mills   schedule 16.12.2013