I’ve just created a simple waepon switch with the enable/disable method. Is there a way to show at the other clients if a mesh is actually showing?
At the moment even if i switch weapon the other client sees the default one.
Thanks
You really expect some help without any code? Are you serious? You didn’t even mentoin the multiplayer framework you are using…
I’m sorry, i’m new to this forum I still learning the rules.
I will post the necessary material as fast as possible.
I’m using the Unity’s network components (manager, HUD, tranform, ecc) and i’m currently trying to implement this code:
using UnityEngine;
public class Shoot : MonoBehaviour {
public Rigidbody projectile;
public Rigidbody rocket;
[SerializeField]
private GameObject shootingPoint;
private Vector3 shootingPosition;
private Quaternion shootingRotation;
public GameObject[] weapons;
private int currentWeapon = 0;
public float speed1 = 20;
public float speed2 = 200;
// Use this for initialization
void Start () {
weapons[0].gameObject.SetActive(true);
weapons[1].gameObject.SetActive(false);
}
// Update is called once per frame
void Update () {
// Shooting
shootingPosition = shootingPoint.transform.position;
shootingRotation = shootingPoint.transform.rotation;
if (currentWeapon == 0) {
if (Input.GetButtonDown("Fire1"))
{
Rigidbody instantiatedProjectile = Instantiate(projectile, shootingPosition, shootingRotation) as Rigidbody;
instantiatedProjectile.velocity = shootingPoint.transform.TransformDirection(new Vector3(0, 0, speed1));
Destroy(instantiatedProjectile, 6.0f);
}
} else if (currentWeapon == 1) {
if(Input.GetButton("Fire1")){
Rigidbody instantiatedRocket = Instantiate(rocket, shootingPosition, shootingRotation) as Rigidbody;
instantiatedRocket.velocity = shootingPoint.transform.TransformDirection(new Vector3(0, 0, speed2));
}
}
// Weapon selector
if (Input.GetKeyDown ("q")) {
if (currentWeapon == 0) {
weapons [0].gameObject.SetActive (false);
weapons [1].gameObject.SetActive (true);
currentWeapon = 1;
} else {
weapons [0].gameObject.SetActive (true);
weapons [1].gameObject.SetActive (false);
currentWeapon = 0;
}
}
}
}
Can i show this change of state on the other clients?
// Weapon selector
if (Input.GetKeyDown ("q")) {
if (currentWeapon == 0) {
weapons [0].gameObject.SetActive (false);
weapons [1].gameObject.SetActive (true);
currentWeapon = 1;
} else {
weapons [0].gameObject.SetActive (true);
weapons [1].gameObject.SetActive (false);
currentWeapon = 0;
}
}
Yes you can but where is your sync function? You need to let the other client know when you switch your weapons via event (rpc).
I followed this doc:
https://docs.unity3d.com/Manual/net-RPCDetails.html
And i put currentWeapon as a [SyncVar] and changed the behaviour from mono to network but it still doesen’t work.
How can i implement a sync function correctly?
I’m photon user, sorry cant’t help you here.
SynVars can ONLY be changed on the server. So you need to send a [Command] to the server to let it know what you want to do