Exemplo n.º 1
0
 public void BallPickup(RugbyAgent ra)
 {
     if (BallPickedUp != null)
     {
         BallPickedUp(teams[ra.teamNumber]);
     }
 }
Exemplo n.º 2
0
 public void Score(RugbyAgent ra)
 {
     if (TeamScored != null)
     {
         TeamScored(teams[ra.teamNumber]);
     }
 }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     cool -= Time.deltaTime;
     if (cool <= 0)
     {
         cool += timeToSpawn;
         NavMeshHit hit;
         if (NavMesh.SamplePosition(new Vector3(
                                        Mathf.Lerp(bounds.xMin, bounds.xMax, Random.value),
                                        0,
                                        Mathf.Lerp(bounds.yMin, bounds.yMax, Random.value)
                                        ), out hit, 1000, NavMesh.AllAreas))
         {
             Ball food = Instantiate(ball);
             food.transform.position = hit.position;
             foreach (Team team in teams)
             {
                 List <RugbyAgent> tAgents = new List <RugbyAgent>();
                 foreach (RugbyAgent agent in agents)
                 {
                     if (teams[agent.teamNumber].name == team.name)
                     {
                         tAgents.Add(agent);
                     }
                 }
                 float      minDist = Mathf.Infinity;
                 RugbyAgent closest = null;
                 foreach (RugbyAgent agent in tAgents)
                 {
                     NavMeshPath path = new NavMeshPath();
                     NavMesh.CalculatePath(agent.transform.position, food.transform.position, NavMesh.AllAreas, path);
                     float thisDist = pathLength(path);
                     if (agent.target == null && thisDist < minDist)
                     {
                         minDist = thisDist;
                         closest = agent;
                     }
                 }
                 if (closest != null)
                 {
                     closest.target = food;
                 }
             }
         }
     }
 }