using UnityEngine; using System.Collections; public class NewMoveLeft : MonoBehaviour { bool lookLeft = false; float currentYAxisSpeed = 0.0f; float speed = 100.0f; float gravity = 10.0f; float airControl = 1.0f; float jumpSpeed = 10.0f; exSprite sprite; exSpriteAnimation spAnim; public GUITexture leftGuiTexture; public GUITexture rightGuiTexture; public GUITexture jumpGuiTexture; CharacterController controller; void Start() { sprite = gameObject.GetComponent(); spAnim = gameObject.GetComponent(); controller = gameObject.GetComponent(); } void FixedUpdate() { checkControls(); calculateFall(); } void calculateFall() { if (controller.isGrounded) { if (!spAnim.IsPlaying("RitterSprung")) { spAnim.SetDefaultSprite(); } } else { currentYAxisSpeed -= gravity * Time.deltaTime; } controller.SimpleMove(Vector3.up * currentYAxisSpeed * Time.deltaTime); } void checkControls() { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { continue; } if (leftGuiTexture.HitTest(touch.position)) { moveLeft(); Debug.Log("BIN LINKS!"); } else if (rightGuiTexture.HitTest(touch.position)) { moveRight(); Debug.Log("BIN RECHTS!"); } else if (jumpGuiTexture.HitTest(touch.position) && controller.isGrounded) { jump(); Debug.Log("BIN GESPRUNGEN!"); } } } void flipDirection() { lookLeft = !lookLeft; sprite.HFlip(); } Vector3 calcWalkDirection() { var direction = (lookLeft ? Vector3.left : Vector3.right) * speed; if (!controller.isGrounded) { direction *= airControl; } return direction; } void startWalkAnimation() { if (controller.isGrounded && !spAnim.IsPlaying("RitterMove")) { spAnim.Play("RitterMove"); } } void move() { startWalkAnimation(); controller.SimpleMove(calcWalkDirection()); } void moveLeft() { if (!lookLeft) { flipDirection(); } move(); } void moveRight() { if (lookLeft) { flipDirection(); } move(); } void jump() { if(!spAnim.IsPlaying("RitterSprung")) { spAnim.Play("RitterSprung"); } currentYAxisSpeed = jumpSpeed; } }