- Home /
object destroy when i shoot on object
i have a people around us (Rigged Humanoid model) so when when i shoot on that they have to dead i have a fps game with Sniper Man who shoot to enemy. but i want too when it shoots to people they also dead help me quick
Answer by MarshCZA · Jul 26, 2017 at 12:49 PM
Are you using projectiles or raycasts to shoot people?
Raycasts can return the target you shot, a quick check to make sure the hit target is an enemy and then you can do Destroy(hit.gameObject)
If you use projectiles you can use their collider to invoke the OnCollisionEnter(Collision col)
and then check that the collider is an enemy. If it is then you can destroy that game object in the same way by doing Destroy(col.gameObject)
i used it but nothing is happen i used Projectiles for bullet
i have using this code for projecting the bullets
Vector3 point = NormalCamera.GetComponent<Camera>().ScreenToWorldPoint (new Vector3 (Screen.width/2, Screen.height/2, 0));
GameObject bullet = (GameObject)Instantiate (Bullets, point, NormalCamera.gameObject.transform.rotation);
bullet.transform.forward = NormalCamera.transform.forward + (new Vector3(Random.Range(-Spread,Spread),Random.Range(-Spread,Spread),Random.Range(-Spread,Spread)) * 0.001f);
Destroy (bullet, LifeTimeBullet);
Okay, do you have a script on the bullets themselves? In that script you need to add an OnCollisionEnter(Collision col)
function for the bullet to interact with whatever it hits
Your answer

Follow this Question
Related Questions
Using Raycast shooting while using a ps4 controller? 0 Answers
Unity Network Laggy projectile 0 Answers
How to make 3 bullets fire at different angles 1 Answer
Shooting bullets in different patterns 0 Answers