- Home /
Question by
syntaxhatasi · Mar 15 at 10:24 AM ·
bullethole
I made a bullet hole, but I don't want the bullet hole to show up in the characters. How do I do that?
In my multiplayer game, I want bullet holes to appear only on the objects of the map. How could I do that? Here's the code:
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingleShotGun : Gun
{
[SerializeField] Camera cam;
PhotonView PV;
void Awake()
{
PV = GetComponent<PhotonView>();
}
public override void Use()
{
Shoot();
}
void Shoot()
{
Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f));
ray.origin = cam.transform.position;
if(Physics.Raycast(ray, out RaycastHit hit))
{
hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)itemInfo).damage);
PV.RPC("RPC_Shoot", RpcTarget.All, hit.point, hit.normal);
}
}
[PunRPC]
void RPC_Shoot(Vector3 hitPosition, Vector3 hitNormal)
{
Collider[] colliders = Physics.OverlapSphere(hitPosition, 0.3f);
if(colliders.Length != 0)
{
GameObject bulletImpactObj = Instantiate(bulletImpactPrefab, hitPosition + hitNormal * 0.001f, Quaternion.LookRotation(hitNormal, Vector3.up) * bulletImpactPrefab.transform.rotation);
Destroy(bulletImpactObj, 10f);
bulletImpactObj.transform.SetParent(colliders[0].transform);
}
}
}
Comment
Answer by Caeser_21 · Mar 15 at 11:42 AM
You could use an if statement like :
if (hit.gameObject.tag != "Player")
{
PV.RPC("RPC_Shoot", RpcTarget.All, hit.point, hit.normal);
}
NOTE : You have to change the "Player" tag according to what tag your player has.
Your answer
![](https://koobas.hobune.stream/wayback/20220613054200im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Bullet Hole Seems to be inside the object not on the surface 1 Answer
bullet hole problem/raycast problem || help me please 1 Answer
Bootcamp particles 0 Answers
Through bullet holes on the objects 0 Answers
Bullet Decals on character 1 Answer