void FixedUpdate() { #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER // the build for PC's control sceheme if (canMove) { Horizontal = Input.GetAxis("Horizontal"); Vertical = Input.GetAxis("Vertical"); Vector3 currentVelocity = gameObject.GetComponent <Rigidbody>().velocity; newVelocityX = 0f; if (Horizontal < 0 && currentVelocity.x <= 0) { newVelocityX = -speed; animator.SetInteger("DirectionX", -1); Up.SetActive(false); Down.SetActive(false); Right.SetActive(false); //TODO play walk sound } else if (Horizontal > 0 && currentVelocity.x >= 0) { newVelocityX = speed; animator.SetInteger("DirectionX", 1); Up.SetActive(false); Down.SetActive(false); Left.SetActive(false); //TODO play walk sound } else { animator.SetInteger("DirectionX", 0); } newVelocityY = 0f; if (Vertical < 0 && currentVelocity.y <= 0) { newVelocityY = -speed; animator.SetInteger("DirectionY", -1); Up.SetActive(false); Left.SetActive(false); Right.SetActive(false); //TODO play walk sound } else if (Vertical > 0 && currentVelocity.y >= 0) { newVelocityY = speed; animator.SetInteger("DirectionY", 1); Down.SetActive(false); Left.SetActive(false); Right.SetActive(false); //TODO play walk sound } else { animator.SetInteger("DirectionY", 0); } if (newVelocityX == 0 && newVelocityY == 0) { Up.SetActive(true); Down.SetActive(true); Left.SetActive(true); Right.SetActive(true); //TODO stop walk sound } if (canMove) //if you can move update the player { gameObject.GetComponent <Rigidbody>().velocity = new Vector3(newVelocityX, 0, newVelocityY); } else { gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero; } } else { Horizontal = 0; Vertical = 0; gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero; DeactivateAllButtons(); } #else //the build for androids controls scheme if (canMove) { Horizontal = 0; Vertical = 0; UpButton = Up.GetComponentInChildren <SimpleTouchArea>(); DownButton = Down.GetComponentInChildren <SimpleTouchArea>(); LeftButton = Left.GetComponentInChildren <SimpleTouchArea>(); RightButton = Right.GetComponentInChildren <SimpleTouchArea>(); Vector3 currentVelocity = gameObject.GetComponent <Rigidbody> ().velocity; newVelocityX = 0f; if (LeftButton.Pressed() && currentVelocity.x <= 0) { newVelocityX = -speed; animator.SetInteger("DirectionX", -1); Up.SetActive(false); Down.SetActive(false); Right.SetActive(false); } else if (RightButton.Pressed() && currentVelocity.x >= 0) { newVelocityX = speed; animator.SetInteger("DirectionX", 1); Up.SetActive(false); Down.SetActive(false); Left.SetActive(false); } else { animator.SetInteger("DirectionX", 0); } newVelocityY = 0f; if (DownButton.Pressed() && currentVelocity.y <= 0) { newVelocityY = -speed; animator.SetInteger("DirectionY", -1); Up.SetActive(false); Left.SetActive(false); Right.SetActive(false); } else if (UpButton.Pressed() && currentVelocity.y >= 0) { newVelocityY = speed; animator.SetInteger("DirectionY", 1); Down.SetActive(false); Left.SetActive(false); Right.SetActive(false); } else { animator.SetInteger("DirectionY", 0); } if (newVelocityX == 0 && newVelocityY == 0) { Up.SetActive(true); Down.SetActive(true); Left.SetActive(true); Right.SetActive(true); } gameObject.GetComponent <Rigidbody> ().velocity = new Vector3(newVelocityX, 0, newVelocityY); } else { Horizontal = 0; Vertical = 0; gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero; DeactivateAllButtons(); } #endif }