fork download
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class NewMoveLeft : MonoBehaviour {
  6.  
  7. bool lookLeft = false;
  8. float currentYAxisSpeed = 0.0f;
  9. float speed = 100.0f;
  10. float gravity = 10.0f;
  11. float airControl = 1.0f;
  12. float jumpSpeed = 10.0f;
  13. exSprite sprite;
  14. exSpriteAnimation spAnim;
  15. public GUITexture leftGuiTexture;
  16. public GUITexture rightGuiTexture;
  17. public GUITexture jumpGuiTexture;
  18. CharacterController controller;
  19.  
  20. void Start()
  21. {
  22. sprite = gameObject.GetComponent<exSprite>();
  23. spAnim = gameObject.GetComponent<exSpriteAnimation>();
  24. controller = gameObject.GetComponent<CharacterController>();
  25. }
  26.  
  27. void FixedUpdate()
  28. {
  29. checkControls();
  30. calculateFall();
  31. }
  32.  
  33. void calculateFall()
  34. {
  35. if (controller.isGrounded)
  36. {
  37. if (!spAnim.IsPlaying("RitterSprung"))
  38. {
  39. spAnim.SetDefaultSprite();
  40. }
  41. }
  42. else
  43. {
  44. currentYAxisSpeed -= gravity * Time.deltaTime;
  45. }
  46.  
  47. controller.SimpleMove(Vector3.up * currentYAxisSpeed * Time.deltaTime);
  48.  
  49. }
  50.  
  51. void checkControls()
  52. {
  53. foreach (Touch touch in Input.touches)
  54. {
  55. if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
  56. {
  57. continue;
  58. }
  59.  
  60. if (leftGuiTexture.HitTest(touch.position))
  61. {
  62. moveLeft();
  63. Debug.Log("BIN LINKS!");
  64.  
  65. }
  66. else if (rightGuiTexture.HitTest(touch.position))
  67. {
  68. moveRight();
  69.  
  70. Debug.Log("BIN RECHTS!");
  71.  
  72. }
  73. else if (jumpGuiTexture.HitTest(touch.position) && controller.isGrounded)
  74. {
  75. jump();
  76. Debug.Log("BIN GESPRUNGEN!");
  77.  
  78. }
  79. }
  80. }
  81.  
  82. void flipDirection()
  83. {
  84. lookLeft = !lookLeft;
  85. sprite.HFlip();
  86. }
  87.  
  88. Vector3 calcWalkDirection()
  89. {
  90. var direction = (lookLeft ? Vector3.left : Vector3.right) * speed;
  91.  
  92. if (!controller.isGrounded)
  93. {
  94. direction *= airControl;
  95. }
  96. return direction;
  97. }
  98.  
  99. void startWalkAnimation()
  100. {
  101. if (controller.isGrounded && !spAnim.IsPlaying("RitterMove"))
  102. {
  103. spAnim.Play("RitterMove");
  104. }
  105. }
  106.  
  107. void move()
  108. {
  109. startWalkAnimation();
  110. controller.SimpleMove(calcWalkDirection());
  111. }
  112.  
  113. void moveLeft()
  114. {
  115. if (!lookLeft)
  116. {
  117. flipDirection();
  118. }
  119.  
  120. move();
  121. }
  122.  
  123. void moveRight()
  124. {
  125. if (lookLeft)
  126. {
  127. flipDirection();
  128. }
  129.  
  130. move();
  131. }
  132.  
  133. void jump()
  134. {
  135. if(!spAnim.IsPlaying("RitterSprung"))
  136. {
  137. spAnim.Play("RitterSprung");
  138. }
  139. currentYAxisSpeed = jumpSpeed;
  140. }
  141. }
  142.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty