Advertisement
soft699

Untitled

Aug 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7.  
  8. //Animation du perso//
  9. Animation animations;
  10.  
  11.  
  12. //Vitesse de déplacement//
  13. public float walkSpeed;
  14. public float runSpeed;
  15. public float turnSpeed;
  16.  
  17. //Inputs//
  18. public string inputFront;
  19. public string inputBack;
  20. public string inputRight;
  21. public string inputLeft;
  22.  
  23. public Vector3 jumpSpeed;
  24. CapsuleCollider playerCollider;
  25.  
  26.  
  27.  
  28.  
  29.  
  30. /// ///////////Fin déclaration variable//////
  31.  
  32. //début void start//
  33. void Start () {
  34.  
  35. animations = gameObject.GetComponent<Animation>();
  36. playerCollider = gameObject.GetComponent<CapsuleCollider>();
  37.  
  38. //fin void start//
  39. }
  40.  
  41.  
  42.  
  43. bool IsGrounded()
  44. {
  45. return Physics.CheckCapsule(playerCollider.bounds.center, new Vector3(playerCollider.bounds.center.x, playerCollider.bounds.min.y - 0.1f, playerCollider.bounds.center.z), 0.11f);
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. //début void update//
  55. void Update () {
  56.  
  57. //avancer//
  58.  
  59. if (Input.GetKey(inputFront) && !Input.GetKey(KeyCode.LeftShift))
  60. {
  61. transform.Translate(0, 0, walkSpeed * Time.deltaTime);
  62. animations.Play("walk");
  63. //reculer//
  64. }
  65. //si on sprint//
  66.  
  67. if (Input.GetKey(inputFront) && Input.GetKey(KeyCode.LeftShift))
  68. {
  69.  
  70. transform.Translate(0, 0, runSpeed * Time.deltaTime);
  71. animations.Play("run");
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. if (Input.GetKey(inputBack))
  83. {
  84. transform.Translate(0, 0, -(walkSpeed /2) * Time.deltaTime);
  85. animations.Play("walk");
  86. }
  87.  
  88. //rotation a gauche//
  89.  
  90. if (Input.GetKey(inputLeft))
  91. {
  92. transform.Rotate(0, -turnSpeed * Time.deltaTime, 0);
  93.  
  94. }
  95.  
  96. //rotation à droite//
  97.  
  98. if (Input.GetKey(inputRight))
  99. {
  100. transform.Rotate(0, turnSpeed * Time.deltaTime, 0);
  101.  
  102. }
  103.  
  104.  
  105.  
  106. //idle//
  107. if (!Input.GetKey(inputFront) && !Input.GetKey(inputBack))
  108. {
  109. animations.Play ("idle");
  110.  
  111. }
  112.  
  113. //Si on saute//
  114.  
  115. if(Input.GetKeyDown(KeyCode.Space) && IsGrounded())
  116. {
  117. //préparation du saut (nécessaire en c#)
  118. Vector3 v = gameObject.GetComponent<Rigidbody>().velocity;
  119. v.y = jumpSpeed.y;
  120.  
  121. //Saut//
  122. gameObject.GetComponent<Rigidbody>().velocity = jumpSpeed;
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223. //fin update//
  224. }
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247. //fin script//
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement