- Home /
Question by
lonelycamper · Jan 21, 2018 at 12:19 AM ·
unity 5networking
properly removing a object out of the scene and syncing it with all clients and properly syncing movement
I'm having trouble syncing my enemy ai object with my clients. The host can see everything properly but my client starts to see the enemy like flashing then when everything syncs it goes to normal but when I kill the ai on the client it doesn't sync to the host or vice versa.
Enemy health script:
public class EnemyHealth : NetworkBehaviour {
[SyncVar]
private bool _isDead = false;
[SerializeField]
private float enemyHealth;
[SerializeField]
private GameObject enemyGFX;
[SerializeField]
private GameObject ragDoll;
[SerializeField]
private GameObject bloodSplatter;
public bool isDead
{
get { return _isDead; }
protected set { _isDead = value; }
}
public void takeDamage(int __amount) {
if (isDead)
return;
enemyHealth -= __amount;
if (enemyHealth <= 0) {
die();
}
}
public void die()
{
GameObject rg = (GameObject)Instantiate(ragDoll, transform.position, Quaternion.identity);
GameObject bS = (GameObject)Instantiate(bloodSplatter, transform.position, Quaternion.identity);
enemyGFX.SetActive(false);
isDead = true;
//CmdOnDie();
My movement script on my ai
if (__distance <= lookRadius)
{
//CmdOnMove();
agent.SetDestination(target.position);
Anim.SetBool("foundPlayer", true);
agent.isStopped = false;
}
if (__distance >= lookRadius)
Anim.SetBool("foundPlayer", false);
if (__distance <= agent.stoppingDistance + shootdistance)
{
// CmdOnStop();
agent.isStopped = true;
Anim.SetBool("foundPlayer", false);
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("idle_aiming"))
{
onShoot();
}
}
}
}
My inspector settings just in case you need them
capture.png
(71.6 kB)
Comment
Better word ins$$anonymous$$d of flashing would be flickering
Your answer
Follow this Question
Related Questions
UNET RPG variable sync help 1 Answer
Question regarding unity mobile multiplayer game 0 Answers
Remote database for leaderboard 2 Answers
Death handling peculiarly 0 Answers