so my programming is as follows.
so right now the client can see the name they have set and the server can see it
when i check the namestring variable on the server it is still blank. it is only set for the client (i checked to make sure)
no matter what i have tried the server will not change the namestring variable on the server that has been set by the client
i can provide any additonal information you may desire
my input field is set up like this
[SyncVar(hook ="hooknametheplayer")]
public string namestring;
public int howmanyplayers;
public bool dashanimation;
public GameObject dashclone;
// Use this for initialization
void hooknametheplayer(string namestring)
{
overheadname.text = namestring;
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Networking;
public class PlayerAttack : BattleControl
{
public float timeBetweenattacks;
public float attackrange;
public Text targetselect;
private bool hastarget;
private bool targetselecton;
bool enemyisinrange;
BoxCollider hitbox;
bool counterstart;
public GameObject[] enemylist;
// Use this for initialization
// sets the starges of the dash
IEnumerator dashstarter()
{
if (dashhelpertwo == true)
{
Cmddasheffect();
GetComponent<Battler>().dashstart = false;
dashnow = true;
yield return new WaitForSeconds(10f * Time.deltaTime);
dashnow = false;
dashforward = false;
dashleft = false;
dashbackward = false;
dashright = false;
attackanimaton.SetInteger("Dashtype", 0);
yield return new WaitForSeconds(dashspeed);
GetComponent<Battler>().dashstart = true;
}
}
[Command]
void Cmddasheffect()
{
dashclone = Instantiate(dasheffect, transform, false);
NetworkServer.Spawn(dashclone);
Destroy(dashclone, 2);
}
//sets the stages of the attack
IEnumerator attack()
{
GetComponent<Battler>().timerstart = false;
attackanimaton.SetBool("attacker", true);
attacksound.Play();
enemyisinrange = true;
yield return new WaitForSeconds(1.0f*Time.deltaTime);
attackanimaton.SetBool("attacker", false);
yield return new WaitForSeconds(attacktime);
GetComponent<Battler>().timerstart = true;
canmovebackwards = true;
canstrafe = true;
canmove = true;
}
void OnTriggerEnter(Collider other)
{
if (!isLocalPlayer)
{
return;
}
target = other.transform;
if (Input.GetMouseButtonDown(0) && GetComponent<Battler>().attacktimer.fillAmount == 1 && other.gameObject.CompareTag("Battler"))
{
if (target == transform || other == gameObject)
{
return;
}
Debug.Log(other);
hitsound.Play();
Cmdhitgraphic();
other.GetComponent<Battler>().takedamage(attackDamage);
other.GetComponent<EnemyControl>().takedamage(attackDamage);
}
}
void OnTriggerStay(Collider other)
{
if (!isLocalPlayer)
{
return;
}
target = other.transform;
if (Input.GetMouseButtonDown(0) && GetComponent<Battler>().attacktimer.fillAmount == 1 && other.gameObject.CompareTag("Battler"))
{
if(target == transform || other == gameObject)
{
return;
}
Debug.Log(other);
hitsound.Play();
Cmdhitgraphic();
other.GetComponent<Battler>().takedamage(attackDamage);
other.GetComponent<EnemyControl>().takedamage(attackDamage);
}
}
void OnTriggerExit(Collider other)
{
}
//Begins Dash lerp
void dashingnow()
{
if (dashnow == true && dashforward == true)
{
attackanimaton.SetInteger("Dashtype", 1);
transform.position = Vector3.Lerp(transform.position, transform.position + transform.forward * dashstat, 10.0f*Time.deltaTime);
}
if (dashnow == true && dashleft == true)
{
attackanimaton.SetInteger("Dashtype", 2);
transform.position = Vector3.Lerp(transform.position, transform.position - transform.right * dashstat, 10.0f * Time.deltaTime);
}
if (dashnow == true && dashbackward == true)
{
attackanimaton.SetInteger("Dashtype", 3);
transform.position = Vector3.Lerp(transform.position, transform.position - transform.forward * dashstat, 10.0f * Time.deltaTime);
}
if (dashnow == true && dashright == true)
{
attackanimaton.SetInteger("Dashtype", 4);
transform.position = Vector3.Lerp(transform.position, transform.position + transform.right * dashstat, 10f * Time.deltaTime);
}
}
[Command]
void Cmdhitgraphic()
{
hitclone = Instantiate(hit, target, false);
NetworkServer.Spawn(hitclone);
Destroy(hitclone, 2);
}
//sets target
void attacking()
{
if (Input.GetMouseButtonDown(0))
{
if (GetComponent<Battler>().attacktimer.fillAmount == 1)
{
canmovebackwards = false;
canstrafe = false;
canmove = false;
attackanimaton.SetFloat("Speed", 0.0f);
attackanimaton.SetBool("attacker", true);
StartCoroutine(attack());
}
{
}
}
}
void targetdeselect()
{
if (Input.GetMouseButtonDown(0))
{
target = null;
targetselecton = true;
}
}
void dashtimerstop()
{
if (inputcounter > 0.2)
{
inputcounter = 0;
}
}
void startdash()
{
if (Input.GetKey(KeyCode.W) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
{
dashhelper = true;
dashforward = true;
}
if (inputcounter > 0.1f && dashforward == true)
{
if (Input.GetKeyDown(KeyCode.W))
{
dashhelpertwo = true;
StartCoroutine(dashstarter());
dashhelpertwo = false;
inputcounter = 0;
dashhelper = false;
GetComponent<Battler>().attacktimer.fillAmount = 0;
}
}
if (Input.GetKey(KeyCode.A) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
{
dashhelper = true;
dashleft = true;
}
if (inputcounter > 0.1f && dashleft == true)
{
if (Input.GetKeyDown(KeyCode.A))
{
dashhelpertwo = true;
StartCoroutine(dashstarter());
dashhelpertwo = false;
inputcounter = 0;
dashhelper = false;
GetComponent<Battler>().attacktimer.fillAmount = 0;
}
}
if (Input.GetKey(KeyCode.S) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
{
dashhelper = true;
dashbackward = true;
}
if (inputcounter > 0.1f && dashbackward == true)
{
if (Input.GetKeyDown(KeyCode.S))
{
dashhelpertwo = true;
StartCoroutine(dashstarter());
dashhelpertwo = false;
inputcounter = 0;
dashhelper = false;
GetComponent<Battler>().attacktimer.fillAmount = 0;
}
}
if (Input.GetKey(KeyCode.D) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
{
dashhelper = true;
dashright = true;
}
if (inputcounter > 0.01f && dashright == true)
{
if (Input.GetKeyDown(KeyCode.D))
{
dashhelpertwo = true;
StartCoroutine(dashstarter());
dashhelpertwo = false;
inputcounter = 0;
dashhelper = false;
GetComponent<Battler>().attacktimer.fillAmount = 0;
}
if (inputcounter > 0.17)
{
inputcounter = 0;
dashhelper = false;
}
}
}
// counts the time bewteen keys that will activate a dash
void dashertiming()
{
if (dashhelper == true)
{
inputcounter += Time.deltaTime;
}
}
// Controls strafing
void strafe()
{
if (canstrafe == true)
{
if (Input.GetKeyDown(KeyCode.A))
{
attackanimaton.SetBool("strafe", true);
attackanimaton.SetFloat("strafing", 1.0f);
var x = Input.GetAxis("Horizontal") * Time.deltaTime * walkspeedstat* 30.0f;
navAgent.speed = 4;
transform.Translate(0, x, 0);
}
if (Input.GetKeyDown(KeyCode.D))
{
attackanimaton.SetBool("strafe", true);
attackanimaton.SetFloat("strafing", 2.0f);
var x = Input.GetAxis("Horizontal") * Time.deltaTime * walkspeedstat * 30.0f;
navAgent.speed = 4;
transform.Translate(0, -x, 0);
}
else if (!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A))
{
attackanimaton.SetBool("strafe", false);
}
}
}
void walkbackwards()
{
if (canmovebackwards == true)
{
if (Input.GetKey(KeyCode.S))
{
attackanimaton.SetBool("backwards", true);
navAgent.speed = 4;
}
else if (!Input.GetKey(KeyCode.S))
{
attackanimaton.SetBool("backwards", false);
}
}
}
//Animates basic movement
void Animate()
{
if (canmove == true)
{
if (Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Vertical") > 0)
{
attackanimaton.SetBool("isAttacking", false);
attackanimaton.SetFloat("Speed", 6.0f);
navAgent.speed = 4;
}
else if (navAgent.velocity.magnitude < 1.0f && (!Input.GetKey(KeyCode.LeftShift)))
{
navAgent.speed = 1;
attackanimaton.SetFloat("Speed", 1.0f);
}
}
}
//displays targeting info
// Controls basic movement
void movement()
{
if (canmove == true)
{
var x = Input.GetAxis("Mouse X")* Time.deltaTime* 150.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * walkspeedstat;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
}
}
void playerlistcannotbezero()
{
if (howmanyplayers < 0)
{
howmanyplayers = enemylist.Length;
}
}
void playerisnamed()
{
if (Input.GetKeyDown(KeyCode.Return))
{
}
}
void targeter()
{
if (Input.GetKeyDown(KeyCode.Z))
{
howmanyplayers -= 1;
targetselect.text = enemylist[howmanyplayers].gameObject.name;
if(howmanyplayers <0)
{
howmanyplayers = enemylist.Length;
}
}
}
public override void OnStartLocalPlayer()
{
enemylist = GameObject.FindGameObjectsWithTag("Battler");
howmanyplayers = enemylist.Length;
thecamera.SetActive(true);
thecamera.GetComponent<CameraControl>().enabled = true;
thecamera.GetComponent<UnityStandardAssets.ImageEffects.CameraMotionBlur>().enabled = true;
thecamera.GetComponent<CameraControl>().cango = true;
Cursor.lockState = CursorLockMode.Confined;
thecamera.GetComponent<CameraControl>().target = mychild;
cameralooking = false;
canmove = true;
canstrafe = true;
canmovebackwards = true;
dashhelpertwo = false;
dashhelper = false;
GetComponent<Battler>().dashstart = true;
GetComponent<Battler>().timerstart = true;
enemyisinrange = false;
targetselecton = true;
GetComponent<Battler>().attacker = false;
hastarget = false;
targetselect.text = ("no target");
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer) {
return; }
mycanvas.transform.LookAt(Camera.main.transform);
strafe();
walkbackwards();
movement();
dashertiming();
dashtimerstop();
startdash();
attacking();
Animate();
dashingnow();
playerlistcannotbezero();
targeter();
}
void LateUpdate()
{
if (!isLocalPlayer) {
return; }
}
}