- Home /
Question by
DimitriUK · Sep 03, 2016 at 05:53 PM ·
c#networkingmultiplayerrpcsynchronization
SyncVar issue
Hello, I am new to creating multiplayer and have done well and now have hit a barrier.
So basically, there is a platform that people can jump on and when they do, it blows up and instantiates an explosion. How it works is OnCollisionEnter, it just SetActive's the sphere to false. At the moment whoever goes on it it only does SetActive false to whoever touched it, as for all the other clients, they can all still see it.
Do I have the SyncVar's in the wrong place? Do I need to use RPC or anything or?? If someone could please help! :)
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class BombCube : NetworkBehaviour {
[SyncVar]
public GameObject Explosion;
[SyncVar]
public GameObject sphere;
[SyncVar]
public bool isMP;
// Use this for initialization
void Start ()
{
sphere = gameObject;
}
public void OnCollisionEnter (Collision other)
{
if (!isMP)
{
if (other.gameObject.tag == "Player")
{
Rigidbody instantiatedProjectileBullet = Instantiate(Explosion, transform.position, transform.rotation) as Rigidbody;
gameObject.SetActive(false);
}
}
if (isMP)
{
if (other.gameObject.tag == "Player")
{
Rigidbody instantiatedProjectileBullet = Instantiate(Explosion, transform.position, transform.rotation) as Rigidbody;
gameObject.SetActive(false); // I want this to disable for all the clients as well, but atm it only disables for whoever hits it
}
}
}
}
Comment