- Home /
Question by
netherboss123 · Apr 04, 2016 at 08:44 AM ·
raycastmultiplayerraycastingshooterpun
Raycasting over Photon Unity Networking
hi! i am making an FPS game that uses PUN and i want to raycast a bullet but when i shoot, nothing happens to the other player i shoot at. This is my code: using System.Collections; using UnityEngine;
public class SniperShoot : Photon.MonoBehaviour {
public Rigidbody rocket;
public GameObject AmmoDisplay;
public int AmmmoPerClip;
public GameObject ClipsDisplay;
public GameObject ReloadText;
public GameObject player;
public float ShootRate;
public float time;
public Rigidbody soundobj;
public int TheAmmoLeft;
public float shootdistance;
public int bulletdamage;
void FireRocket () {
time = ShootRate;
PhotonNetwork.Instantiate(rocket.name, transform.position, transform.rotation, 0);
PhotonNetwork.Instantiate(soundobj.name, transform.position, transform.rotation, 0);
AmmoDisplay.GetComponent<ShowAmmo>().ammoleft -= 1;
}
void Update () {
TheAmmoLeft = AmmoDisplay.GetComponent<ShowAmmo>().ammoleft;
time -= Time.deltaTime;
if (Input.GetButton("Fire1")) {
if (time <= 0){
if (TheAmmoLeft >= 1){
RaycastHit hit;
Ray ray = new Ray (transform.position, transform.forward);
if (Physics.Raycast (ray, out hit, shootdistance)){
if (hit.collider.gameObject.tag == "Player"){
hit.collider.GetComponent<Health>().PlayerHealth -= bulletdamage;
}
}
FireRocket();
}
}
}
if (TheAmmoLeft <= 0){
ReloadText.SetActive (true);
} else {
ReloadText.SetActive (false);
}
if (Input.GetButtonDown("R")){
StartCoroutine(Reload());
}
}
IEnumerator Reload(){
yield return new WaitForSeconds (2);
AmmoDisplay.GetComponent<ShowAmmo>().ammoleft = AmmmoPerClip;
ClipsDisplay.GetComponent<ShowClips>().clipsleft -= 1;
}
}
Please help me!!
Comment
Your answer
Follow this Question
Related Questions
[C#] UNET Client raycast not the same as Server raycast 2 Answers
Fixing Editor Mouse Offset Due To Local Raycast? 1 Answer
[CLOSED]RaycastAll Help 1 Answer
RayCast or LineCast? 1 Answer
Play Animation on Raycast *open and close some objects* 0 Answers