Exemplo n.º 1
0
    void CreateUnit()
    {
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100, unitMask))
        {
            Vector3 navMeshUnitPosition = hit.point;
            navMeshUnitPosition.y = 0.75f;
            NavMeshAgent   agent    = Instantiate(navMeshUnitPrefab, navMeshUnitPosition, Quaternion.identity).GetComponent <NavMeshAgent> ();
            FollowNavAgent follower = Instantiate(unitPrefab, hit.point, Quaternion.identity).GetComponent <FollowNavAgent> ();
            follower.agent        = agent;
            follower.raycastPoint = agent.transform.GetChild(0);
        }
    }
Exemplo n.º 2
0
 void OnDeath()
 {
     unitSelection.RemoveTower(this);
     unitSelection.towersDestroyedCount++;
     for (int i = 0; i < numUnitsOnDeath; i++)
     {
         Vector3 randomPos = transform.position + Random.insideUnitSphere * 4f;
         randomPos.y = transform.position.y;
         Vector3 navMeshUnitPosition = randomPos;
         navMeshUnitPosition.y = 0.75f;
         NavMeshAgent   agent    = Instantiate(navMeshUnitPrefab, navMeshUnitPosition, Quaternion.identity).GetComponent <NavMeshAgent>();
         FollowNavAgent follower = Instantiate(unitPrefab, randomPos, Quaternion.identity).GetComponent <FollowNavAgent>();
         follower.agent        = agent;
         follower.raycastPoint = agent.transform.GetChild(0);
     }
 }
Exemplo n.º 3
0
    void CreateUnitAtSpawnSpot()
    {
        RaycastHit hit;
        Transform  raycastPoint = spawnSpots[Random.Range(0, spawnSpots.Length)];
        Vector3    ray          = raycastPoint.TransformDirection(Vector3.down) * 100;

        if (Physics.Raycast(raycastPoint.position, ray, out hit, 100, terrainMask))
        {
            Vector3 randomPos = hit.point + Random.insideUnitSphere * 4f;
            randomPos.y = hit.point.y;
            Vector3 navMeshUnitPosition = randomPos;
            navMeshUnitPosition.y = 0.75f;
            NavMeshAgent   agent    = Instantiate(navMeshUnitPrefab, navMeshUnitPosition, Quaternion.identity).GetComponent <NavMeshAgent>();
            FollowNavAgent follower = Instantiate(unitPrefab, randomPos, Quaternion.identity).GetComponent <FollowNavAgent>();
            follower.agent        = agent;
            follower.raycastPoint = agent.transform.GetChild(0);
        }
    }