- Home /
Enemy bleeding
I need to make my gun understand that if I shoot the wall or ground a bullet mark will appear but if I shoot my enemy a blood splatter will show. How can I make this happen? I have the bullet mark working fine but it still shows on my enemy.
public GameObject BulletMark;
public GameObject Blood;
void Shoot(){
animation.Play();
audio.Play();
//Normal Raycast //Add a random value to mouse position(r
ray = Camera.main.ScreenPointToRay(Input.mousePosition+Random.insideUnitSphere*GunRecoil);
if(Physics.Raycast(ray, out hit, 10)){
//Declear new GameObject variable
GameObject BulletHole;
//Create the shootmark prefab at the hit point
BulletHole = Instantiate (BulletMark, hit.point+(hit.normal*0.001f), transform.rotation) as GameObject;
//Rotate the created object at the face of the normal LookAt (hit.point+hit.normal)
BulletHole.transform.LookAt(hit.point+hit.normal);
BulletHole.transform.parent=hit.transform;
hit.transform.gameObject.SendMessage("Hit", 5, SendMessageOptions.DontRequireReceiver);
}
Answer by Ejlersen · Aug 06, 2013 at 08:44 PM
You can use layers to do this, e.g. if enemy is in the layer: "Enemy" and wall is in "Wall", then you can check if the hit.transform.gameObject.layer is either enemy or wall.
Example:
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Enemy"))
{
// Make him bleed!
}
else if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Wall"))
{
// Make hole
}
I am not sure if I understand how to add this line. I am using enemy as layer and wall as layer but I'm not sure how to make this part work.
I'm sorry but this did not work. I added the right layer name and everything correct but I got an error message saying something is wrong with this specific line making none of them to show.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111650im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make my enemy bleed 1 Answer
Blood splatter when shot? 0 Answers
How do I use particles to make blood spurt from an enemy when you shoot it? 1 Answer
Machine gun help 1 Answer