- Home /
Multiplayer FPS Fail
Hey, im making a multiplayer fps, all network and server s**t is done, now I created the raycast script for shooting, but when i try this is multiplayer, when I shoot, the otherone also shoot. Here is my script:
var Range : float = 1000;
var Force : float = 1000;
var Clips : int = 3;
var BulletsPerClip : int = 7;
var Reload : float = 3.3;
var BulletsLeft : int = 0;
var ShootTimer : float = 0;
var ShootCooler : float = 0.9;
public var ShootAudio : AudioClip;
public var ReloadAudio : AudioClip;
function Start(){
BulletsLeft = BulletsPerClip;
}
function Update () {
if(Input.GetMouseButtonDown(0)){
RayShoot();
}
}
function RayShoot() {
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, DirectionRay * Range, Color.yellow);
if(Physics.Raycast(transform.position, DirectionRay, Hit, Range)){
if(Hit.rigidbody){
Hit.rigidbody.AddForceAtPosition(DirectionRay * Force, Hit.point);
}
}
}
function ReloadGun(){
}
function PlayShootAudio(){
}
function PlayReloadAudio(){
}
So can someone help me ??
Answer by Duke Euphoria · Oct 04, 2012 at 06:25 PM
Try This...
The Extra clause in the if statement means it will only fire if the script is controlled by the local machine.
function Update ()
{
if(Input.GetMouseButtonDown(0) && networkView.isMine)
{
RayShoot();
}
}
Answer by Hybris · Jun 28, 2012 at 08:39 AM
If you press the LMB all of the script activate. So you have to define the players or something like that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613073414im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Need help with basic networking 2 Answers
Help with server creation and handling. 0 Answers
Cant Kill Multiplayer Player In Unity, Help! 0 Answers
Multiplayer FPS Tutorial 1 Answer