So my game follows a client server system
for some reason the server only behaves correctly when it is activated in the editor.
the networking is correct i can connect to the server if i run if outside of the editor
but my damage hook will not work correctly
however if i run the server in the editor and client outside of the editor it connects and the hook is carried correctly
here is the stats script which handles damage currently i can supple any info you think might be necessary
keep in mind this script works perfectly applying damage when the server is in the editor
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class Stats : NetworkBehaviour
{
public bool hasbeenattacked;
List<GameObject> party = new List<GameObject>();
public List<GameObject> attackerslist = new List<GameObject>();
public Transform head;
[SyncVar]
public int level;
[SyncVar]
public string username;
[SyncVar(hook = "hphook")]
public float myhp;
[SyncVar]
public float hp;
public bool dualwield;
public GameObject weapontwo;
[SyncVar]
public float currenthp;
public float attacklisttimer;
public float staminacost;
[SyncVar]
public float maxhp;
public float stamina;
public float currentstamina;
public float maxstamina;
public float speed;
public float currentspeed;
public float maxspeed;
public float strength;
public float currentstrength;
[SyncVar]
public string charactername;
public float maxstrength;
public GameObject hpbar;
[SyncVar]
public float damage;
public GameObject shield;
public GameObject weapon;
public Animator anim;
public Slider externalhpbar;
public Slider staminabar;
public Slider externalstaminabar;
public bool checkhp;
public Text nametext;
public GameObject player;
public InputField setcharactername;
public GameObject okbutton;
public GameObject nameinput;
public GameObject externalguistamina;
public bool growstamina;
public bool timerstart;
public float timetillfullstamina;
public GameObject arrow;
public float staminagain;
public float staminagaintime;
public float circlevalue;
public Image circlehp;
public AudioClip shieldblock;
public AudioClip gethit;
public AudioClip death;
public AudioClip selectobject;
public AudioSource playeraudio;
public GameObject targeting;
public GameObject nameblock;
public GameObject weaponone;
public GameObject UIuseobject;
public bool noshield;
[SyncVar]
public int xp;
[SyncVar]
public int xpgain;
private int originalCount;
void circlehpchange()
{
circlevalue = 1 - currenthp;
circlehp.CrossFadeAlpha(circlevalue, 0.5f, true);
}
public void takingdamage(float damage)
{
{
if (!isServer)
{
return;
}
anim.SetTrigger("gethit");
playeraudio.clip = gethit;
playeraudio.Play();
Rpc_hit();
hp -= damage;
currenthp = hp / maxhp ;
externalhpbar.value = Mathf.Lerp(externalhpbar.value, currenthp, 1f);
if (myhp <= 0 && this.transform == this.transform.root)
{
playeraudio.clip = GetComponent<Stats>().death;
playeraudio.Play();
if (isServer && transform.tag != "player")
{
if (attackerslist.Count > 1)
{
foreach (GameObject player in attackerslist)
{
player.GetComponent<Stats>().xp += xpgain;
}
}
}
Rpc_died();
Destroy(this.gameObject);
}
}
}
[ClientRpc]
void Rpc_hit()
{
anim.SetTrigger("gethit");
playeraudio.clip = gethit;
playeraudio.Play();
}
public void setmyname()
{
charactername = setcharactername.text;
nametext.text = charactername;
Cmd_setname(charactername);
okbutton.SetActive(false);
nameinput.SetActive(false);
}
[Command]
public void Cmd_setname(string charactername)
{
nametext.text = charactername;
Rpc_setname(charactername);
}
[ClientRpc]
public void Rpc_setname(string charactername)
{
nametext.text = charactername;
}
void hphook(float hp)
{
currenthp = hp / maxhp;
externalhpbar.value = Mathf.Lerp(externalhpbar.value, currenthp, 15f);
}
void staminafilling()
{
if (growstamina == true)
{
StartCoroutine(staminafiller());
if (stamina >= maxstamina)
{
growstamina = false;
timerstart = false;
}
}
}
void staminanotfull()
{
if (stamina != maxstamina && timerstart == false)
{
StartCoroutine(staminafill());
}
}
IEnumerator staminafiller()
{
if (growstamina == true && stamina < maxstamina)
{
stamina += staminagain;
yield return new WaitForSeconds(staminagaintime);
StartCoroutine(staminafiller());
if (stamina >= maxstamina)
{
growstamina = false;
timerstart = false;
}
StopCoroutine(staminafiller());
}
}
IEnumerator staminafill()
{
timerstart = true;
yield return new WaitForSeconds(timetillfullstamina);
growstamina = true;
}
[ClientRpc]
void Rpc_died()
{
playeraudio.clip = GetComponent<Stats>().death;
playeraudio.Play();
Destroy(this.gameObject);
}
void strengthdamage()
{
}
void staminacalculate()
{
currentstamina = stamina / maxstamina;
staminabar.value = Mathf.Lerp(staminabar.value, currentstamina, 15f);
externalstaminabar.value = Mathf.Lerp(externalstaminabar.value, currentstamina, 15f);
}
[Command]
void Cmd_addtoparty(GameObject player)
{
party.Add(player);
}
public void addtoattackers(GameObject player)
{
attackerslist.Add(player);
hasbeenattacked = true;
if(isLocalPlayer)
{
Cmd_addtoattackers(player);
Cmd_attacked(hasbeenattacked);
}
if(isServer)
{
Rpc_addtoattackers(player);
Rpc_attacked(hasbeenattacked);
}
if(hasbeenattacked == true)
{
StartCoroutine(attacklisttime());
hasbeenattacked = false;
if (isLocalPlayer)
{
Cmd_attacked(hasbeenattacked);
}
if (isServer)
{
Rpc_attacked(hasbeenattacked);
}
}
}
public IEnumerator attacklisttime()
{
yield return new WaitForSeconds(attacklisttimer * Time.deltaTime);
if(isLocalPlayer)
{
attackerslist.Clear();
}
if(isServer && transform.tag == "enemy")
{
attackerslist.Clear();
}
}
[Command]
void Cmd_removefromattackers(GameObject player)
{
attackerslist.Remove(player);
Rpc_removefromattackers(player);
}
[ClientRpc]
void Rpc_removefromattackers(GameObject player)
{
{
attackerslist.Remove(player);
}
}
public void restarttime()
{
StopCoroutine(attacklisttime());
StartCoroutine(attacklisttime());
if(isLocalPlayer)
{
Cmd_restarttime();
}
if(isServer)
{
Rpc_restarttime();
}
}
[Command(channel = 3)]
void Cmd_restarttime()
{
StopCoroutine(attacklisttime());
StartCoroutine(attacklisttime());
Rpc_restarttime();
}
[ClientRpc(channel = 3)]
void Rpc_restarttime()
{
StopCoroutine(attacklisttime());
StartCoroutine(attacklisttime());
}
[ClientRpc]
void Rpc_attacked(bool attacked)
{
hasbeenattacked = attacked;
}
[Command]
void Cmd_attacked (bool attacked)
{
hasbeenattacked = attacked;
Rpc_attacked(attacked);
}
[ClientRpc(channel = 3)]
void Rpc_addtoattackers(GameObject player)
{
attackerslist.Add(player);
}
[Command(channel = 3)]
void Cmd_addtoattackers(GameObject player)
{
attackerslist.Add(player);
Rpc_addtoattackers(player);
}
// Use this for initialization
void Start()
{
anim =GetComponent<Animator>();
if (GetComponent<Charactersize>() != null)
{
if (GetComponent<Charactersize>().weight > 200 && transform.tag != "player")
{
GetComponent<AItargeting>().playertoofar *= 4;
}
}
if (transform.tag == "player")
{
party.Add(gameObject);
if (isLocalPlayer)
{
Cmd_addtoparty(gameObject);
}
circlehp.canvasRenderer.SetAlpha(0.0f);
}
if (isLocalPlayer)
{
hpbar.SetActive(false);
externalguistamina.SetActive(false);
nameblock.SetActive(false);
}
if (!isLocalPlayer)
{
if (transform.tag == "player")
{
okbutton.SetActive(false);
nameinput.SetActive(false);
}
}
}
// Update is called once per frame
void Update()
{
myhp = hp;
if (transform.tag == "player" && isLocalPlayer)
{
staminacalculate();
staminanotfull();
staminafilling();
circlehpchange();
}
}
}
this is the current channel configuration