// Update is called once per frame void Update() { if (SceneManager.GetActiveScene().name == "LoadScreen") return; if (mListener == null && isServer) mListener = GameObject.Find("WorldState").GetComponent<spt_Network_MovementListener>(); if (!isLocalPlayer) return; //if this player is not server, have it update the current thumbstick input to the server if (!isServer && (Mathf.Abs(spt_playerControls.leftThumb("Vertical") - lastCli_lStick) >= THRESHOLD)) { lastCli_lStick = spt_playerControls.leftThumb("Vertical"); if (bumpers()) CmdSendLStickIn(-1.0f * lastCli_lStick); else CmdSendLStickIn(0.0f); return; } //get left thumb stick input. lStickInput = spt_playerControls.leftThumb("Vertical"); /* DEBUG Movement Check if (Input.GetKey(KeyCode.F10)) { lStickInput = 2.0F; } */ //if the left thumb stick input is greater than threshold... if (mListener.aggregateLStickInput > 1.5F) { //if it's the server, just move it since we own the object. Client won't do anything if (isServer && bumpers()) { moveHost(new Vector3(0.0F, 0.0F, 1.0F)); moveSound.Play(); animator.SetInteger("animation", 2); hostAnimator_var = 2; } } //if its greater than the negative threshold, move in opposite direction else if (mListener.aggregateLStickInput < -1.5F) { if (isServer && bumpers()) { moveHost(new Vector3(0.0F, 0.0F, -1.0F)); moveSound.Play(); animator.SetInteger("animation", 1); hostAnimator_var = 1; } } else { //otherwise ensure animator in rest state moveSound.Stop(); animator.SetInteger("animation", 0); hostAnimator_var = 0; } //if this isn't the server... if (!isServer) { //first update clientAnimator_Var clientAnimator_var = host.GetComponent<spt_Network_Movement>().hostAnimator_var; animator.SetInteger("animation", clientAnimator_var); //move my transform such that it always syncs with hosts movement. Vector3 newTrans = host.transform.position; newTrans.z -= playerSeperation; this.transform.position = newTrans; //pSpawn.transform.position = newTrans; } }
void Start() { if (SceneManager.GetActiveScene().name == "LoadScreen") return; mListener = GameObject.Find("WorldState").GetComponent<spt_Network_MovementListener>(); lStickInput = 0.0F; //if this is the host player, assign it the gameobject if (isServer) host = this.gameObject; //otherwise find the host player and set the reference so we can get it's position. else { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach ( GameObject player in players) { if (this.gameObject != player) { host = player; break; } } } linkModelPrefab(); linkSpawnPrefab(); hostAnimator_var = 0; clientAnimator_var = 0; }