
It looks like you're new here. If you want to get involved, click one of these buttons!
when the FPS player shoots downwards he shoots himself and I don't want that. But if I make the player ignore raycasts (layer) then other players won't be able to shoot him. how can I make it such that the player can't shoot himself but other players can? I used a character controller for the player movement(as seen in Brackeys tutorial) and below is the code for the gun script. pls help cuz im new to coding :[
I
I
I
V
using UnityEngine;
public class Gun : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
public Camera fpsCam;
void Update()
{
if (Input.GetButton("Fire1"))
{
Shoot();
}
void Shoot()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
}
}
}
}