- Home /
how to raycast instantiated game characters
I made a fPS shooter that has instantiated enemies coming at you. My problem is how do you destroy the copy of the enemy's by raycasting? I ran some tests with original enemy object and it works fine....but when the enemy is instantiated it doesn't work... thanks a lot to anybody that can help me.....
Comment
It shouldn't work any differently! Are you sure you're doing the right thing? Can you modify your post to include some code snippets of the bit in question?
Answer by scarpelius · Oct 22, 2011 at 07:07 AM
I haven't test it but the information about the hit object is contained in the hit variable, something like this:
RaycastHit hit;
Physics.Raycast(playerPosition, Vector3.forward, out hit);
Destroy(hit.transform.gameObject);
Code is C#.