Advertisement
rdgorodrigo

Untitled

Jul 23rd, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class Tortuga : MonoBehaviour
  6. {
  7.  
  8. private Animator anim;
  9. private CharacterController controller;
  10.  
  11. public float speed = 6.0f;
  12. public float turnSpeed = 60.0f;
  13. private Vector3 moveDirection = Vector3.zero;
  14. public float gravity = 20.0f;
  15. public string horizontalCtrl = "Horizontal_P2";
  16. public string verticalCtrl = "Vertical_P2";
  17. public float coeffSpeedUp = 1.0f;
  18.  
  19.  
  20. // Use this for initialization
  21. void Start ()
  22. {
  23.  
  24. controller = GetComponent <CharacterController> ();
  25. anim = gameObject.GetComponentInChildren<Animator> ();
  26. }
  27.  
  28. // Update is called once per frame
  29. void Update ()
  30. {
  31.  
  32. if (Input.GetKey ("i"))
  33. {
  34. anim.SetInteger ("IsWalking", 1);
  35. } else {
  36. anim.SetInteger ("IsWalking", 0);
  37. }
  38.  
  39. if (controller.isGrounded)
  40. {
  41. moveDirection = transform.forward * Input.GetAxis (verticalCtrl) * coeffSpeedUp;
  42.  
  43. }
  44.  
  45.  
  46. float turn = Input.GetAxis(horizontalCtrl);
  47. transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
  48. controller.Move(moveDirection * Time.deltaTime);
  49. moveDirection.y -= gravity * Time.deltaTime;
  50. }
  51. public IEnumerator StopSpeedUp() {
  52. yield return new WaitForSeconds (4.0f); // the number corresponds to the nuber of seconds the speed up will be applied
  53. coeffSpeedUp = 4.0f;
  54. // back to normal !
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement