Guest User

Untitled

a guest
Jan 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class Jogador : MonoBehaviour {
  7. public Transform bola;
  8. public Transform posicao;
  9.  
  10. public NavMeshAgent nma;
  11.  
  12. public Vector3 DisPosicao;
  13. public Vector3 DirChute;
  14.  
  15. public bool Chutou;
  16. public bool Passou;
  17.  
  18. public float ForcaNormal = 200;
  19. public float ForcaChute = 800;
  20. public float VelocidadeNorm = 8;
  21. public float VelocidadeMax = 16;
  22. public float VelocidadeAtual;
  23.  
  24. void Start()
  25. {
  26. }
  27.  
  28. void Update()
  29. {
  30. nma.speed = VelocidadeAtual;
  31.  
  32. if (!bola){
  33. if(posicao)
  34. nma.destination = posicao.position + DisPosicao;
  35.  
  36. return;
  37. }
  38.  
  39. nma.destination = bola.position;
  40.  
  41. if(Vector3.Distance(transform.position, bola.position) > 1)
  42. return;
  43.  
  44. if(!Chutou && !Passou)
  45. {
  46. (GetBolaRB()).AddForce(DirChute * (ForcaNormal + VelocidadeAtual) + Vector3.up * 15);
  47. }
  48. else if(Chutou)
  49. {
  50. Chutar();
  51. }
  52. else if(Passou)
  53. {
  54. Passar();
  55. }
  56. }
  57.  
  58. private Rigidbody GetBolaRB()
  59. {
  60. if (bola == null)
  61. throw return;
  62.  
  63. return bola.GetComponent<Rigidbody>();
  64. }
  65.  
  66. protected float GetForcaChutePasse()
  67. {
  68. return ForcaNormal + VelocidadeAtual + ForcaChute;
  69. }
  70.  
  71. protected void Chutar(){
  72. Chutou = false;
  73. Passou = false;
  74.  
  75. float forcaFinal = GetForcaChutePasse();
  76. (GetBolaRB()).AddForce(DirChute * (forcaFinal) + Vector3.up * 15);
  77. }
  78.  
  79. protected void Passar()
  80. {
  81. Vector3 position = transform.position;
  82. float dis = -1;
  83. Passou = false;
  84.  
  85. for(int i = 0; i < Time.jogadores.Count; i++)
  86. {
  87. if(Time.jogadores[i] != this)
  88. {
  89. var disAtual = Vector3.Distance(Time.jogadores[i].transform.position, position);
  90. if(dis == -1 || dis < disAtual)
  91. {
  92. dis = disAtual;
  93. Time.jogador = i;
  94. }
  95. }
  96. }
  97.  
  98. Vector3 jogadorPosition = Time.jogadores[Time.jogador].transform.position;
  99. float forcaFinal = GetForcaChutePasse();
  100.  
  101. (GetBolaRB()).AddForce((jogadorPosition - position).normalized * (forcaFinal) + Vector3.up * 15);
  102. Time.jogadores[Time.jogador].bola = bola;
  103. bola = null;
  104. }
  105. }
Add Comment
Please, Sign In to add comment