- Home /
Question by
Zypher · May 24, 2014 at 12:00 AM ·
script.raycasthit2d
Problem with Tapping Script.
I created a GameController, and its job is to spawn by sprite. Now I want to destroy the spawns with just a single tap.
This is the script that attached to the main camera:
if (Input.touchCount > 0)
{
var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint((Input.GetTouch(0).position)), Vector2.zero);
if(hit.collider != true)
{
Destroy(hit.transform.gameObject);
}
}
Then I attached the script below to the prefab that I inserted into the GameController:
function OnTriggerEnter(other:Collider){
Destroy(other.gameObject);
}
I even added box colliders to the GameController, Prefab, and Main Camera; they are all triggers. What am I doing wrong?
Comment
Shouldn't hit.collider be compared with null ins$$anonymous$$d?