Ive been trying to use this, but its not working. It wont even log “Ray Sent.” This code is placed in the Update Function of my player.
Vector3 rot = new Vector3 (gameObject.GetComponentInChildren<Camera> ().transform.position.x, transform.position.y, 0);
Vector3 fwd = gameObject.GetComponentInChildren<Camera>().transform.TransformDirection (Vector3.forward);
RaycastHit hit;
if (Physics.Raycast (transform.position, rot, out hit)) {
Debug.Log ("Ray Sent.");
if (hit.distance <= 5 && hit.collider.gameObject.tag == "Item") {
UnityEngine.Networking.NetworkServer.Destroy (hit.collider.gameObject);
}
}