Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class Jogador : MonoBehaviour {
- public Transform bola;
- public Transform posicao;
- public NavMeshAgent nma;
- public Vector3 DisPosicao;
- public Vector3 DirChute;
- public bool Chutou;
- public bool Passou;
- public float ForcaNormal = 200;
- public float ForcaChute = 800;
- public float VelocidadeNorm = 8;
- public float VelocidadeMax = 16;
- public float VelocidadeAtual;
- void Start()
- {
- }
- void Update()
- {
- nma.speed = VelocidadeAtual;
- if (!bola){
- if(posicao)
- nma.destination = posicao.position + DisPosicao;
- return;
- }
- nma.destination = bola.position;
- if(Vector3.Distance(transform.position, bola.position) > 1)
- return;
- if(!Chutou && !Passou)
- {
- (GetBolaRB()).AddForce(DirChute * (ForcaNormal + VelocidadeAtual) + Vector3.up * 15);
- }
- else if(Chutou)
- {
- Chutar();
- }
- else if(Passou)
- {
- Passar();
- }
- }
- private Rigidbody GetBolaRB()
- {
- if (bola == null)
- throw return;
- return bola.GetComponent<Rigidbody>();
- }
- protected float GetForcaChutePasse()
- {
- return ForcaNormal + VelocidadeAtual + ForcaChute;
- }
- protected void Chutar(){
- Chutou = false;
- Passou = false;
- float forcaFinal = GetForcaChutePasse();
- (GetBolaRB()).AddForce(DirChute * (forcaFinal) + Vector3.up * 15);
- }
- protected void Passar()
- {
- Vector3 position = transform.position;
- float dis = -1;
- Passou = false;
- for(int i = 0; i < Time.jogadores.Count; i++)
- {
- if(Time.jogadores[i] != this)
- {
- var disAtual = Vector3.Distance(Time.jogadores[i].transform.position, position);
- if(dis == -1 || dis < disAtual)
- {
- dis = disAtual;
- Time.jogador = i;
- }
- }
- }
- Vector3 jogadorPosition = Time.jogadores[Time.jogador].transform.position;
- float forcaFinal = GetForcaChutePasse();
- (GetBolaRB()).AddForce((jogadorPosition - position).normalized * (forcaFinal) + Vector3.up * 15);
- Time.jogadores[Time.jogador].bola = bola;
- bola = null;
- }
- }
Add Comment
Please, Sign In to add comment