Raycast problem (FPS Tutorial)

Updated on March 28, 2018 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on September 2, 2017

 I have a problem with my code

 

When i shoot nothing happens

using UnityEngine;
using UnityEngine.Networking;
public class PlayerShoot : NetworkBehaviour
{
private const string PLAYER_TAG = "Player";
public PlayerWeapons weapon;
[SerializeField]
 private Camera cam;
[SerializeField]
 private LayerMask mask;
void Start()
 {
 if (cam == null)
 {
 Debug.LogError("PlayerShoot: No camera referenced!");
 this.enabled = false;
 }
 }
void Update()
 {
 if (Input.GetButtonDown("Fire1"))
 {
 Shoot();
 }
 }
[Client]
 void Shoot()
 {
 RaycastHit _hit;
 if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, weapon.range, mask))
 {
 if (_hit.collider.tag == PLAYER_TAG)
 {
 CmdPlayerShot(_hit.collider.name);
 }
 }
}
[Command]
 void CmdPlayerShot(string _ID)
 {
 Debug.Log(_ID + " has been shot.");
 }
}

pls help

 

I dont get any errors!

 

  • Liked by
Reply
1 on September 3, 2017

Sorry, already fixed

🙂

on March 28, 2018

How??

 

Show more replies
  • Liked by
Reply
Cancel