RPC call only on same object

Hi,
I have 3 player on the scene. And I have Shoot.cs on them. At shoot.cs i have shoot and remoteshoot functions. When i call remote shoot all players in the scene are shooting but i only want me and my clones on other players will shoot. How can i make it ?

RaycastHit hit;

private void Shoot()
{
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(shootPositionTransform.position, shootPositionTransform.forward, out hit,
gunProperties.range, interactibleLayers))
{
if (photonView.IsMine)
{
_nextShootTime = Time.time + gunProperties.coolDown;
_magCurrentAmmoCount.Value -= 1;
_totalAmmoCount.Value -= 1;
// Debug.DrawRay(shootPositionTransform.position, shootPositionTransform.forward * hit.distance, Color.yellow);
Debug.Log("Did Hit");
photonView.RPC("RemoteShoot", RpcTarget.All, shootPositionTransform.position);
}
else
{
}
}
else
{
// Debug.DrawRay(shootPositionTransform.position,
// shootPositionTransform.TransformDirection(Vector3.forward) * gunProperties.range,
// Color.magenta);
Debug.Log("Did not Hit");
}
}
[PunRPC]
private void RemoteShoot(Vector3 raycastPos)
{
Debug.Log("Shoot");
if (Physics.Raycast(raycastPos, transform.forward, out hit,
gunProperties.range, interactibleLayers))
{
Debug.DrawRay(raycastPos,
raycastPos + Vector3.forward * gunProperties.range,
Color.green);
//IF hit level object then make decal
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("LevelObject"))
{

CreateDecal(hit.point, Quaternion.Inverse(transform.rotation), gunProperties.itemType);
}
//Else means its and hittable object call hit method
else
{
HitToHitableObject(hit.transform, gunProperties.damage);
}
}
}



Comments

Sign In or Register to comment.