Answer the question
In order to leave comments, you need to log in
Unity - Problem with "if"?
Hello!
I'm having a problem with a multiplayer game:
There is "Player 1" who is supposed to run the game in Unity and "Player 2" who is playing through the compiled file of the same game. (It doesn't matter who holds the localhost (I checked)).
When a player who launched the game in Unity (LocalPlayer) shoots and hits another player (RemotePlayer), "test_1" is displayed in the Unity console, but if a player in a separate application (RemotePlayer) shoots at a player (LocalPlayer) "test_1" does not appear although it should . Also, for some reason, the last part of the code is not displayed in the console: "Debug.Log ("The player " + _ID + " fired a shot");" .
Ps: Probably a problem in Playershoot.sc
using UnityEngine;
using UnityEngine.Networking;
public class PlayerShoot : NetworkBehaviour {
public Weapon weapon;
[SerializeField]
private Camera cam;
[SerializeField]
private LayerMask mask;
void Start () {
if (cam == null) {
Debug.LogError ("PlayerShoot: No camera found");
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")
CmdPlayerShoot (_hit.collider.name);
Debug.Log ("Test_1");
}
}
[Command]
void CmdPlayerShoot (string _ID) {
Debug.Log ("В игрока " + _ID + " произвел выстрел");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question