Exemplo n.º 1
0
    private void SetToTrash()
    {
        float randomX = Random.Range(-1, 1);
        float randomY = Random.Range(-1, 1);

        Vector3 waypointLocation = LeafManager.main.ReturnWaypointLeafIsAt(this).transform.position;

        Vector3 locationToSpawn = new Vector3(
            waypointLocation.x + randomX,
            waypointLocation.y + randomY,
            waypointLocation.z
            );

        GameObject trashGameObject = Instantiate(
            TrashManager.main.TrashPrefab(),
            locationToSpawn,
            new Quaternion(0, 0, 0, 0),
            TrashManager.main.gameObject.transform
            );

        Trash trash = trashGameObject.GetComponent <Trash>();

        trash.SetLayer(Trash.Layer.UNDERGROUND);
        FlowManager.main.AddTrashToAllConnectedRoads(LeafManager.main.ReturnWaypointLeafIsAt(this));
        trash.AssignOneWaypoint(LeafManager.main.ReturnWaypointLeafIsAt(this));
        TrashManager.main.CreatedNewTrash(trash);
        TrashManager.main.AddTrashToWaypoints(trash, LeafManager.main.ReturnWaypointLeafIsAt(this));
        LeafManager.main.LeafDeath(this, LeafManager.main.ReturnWaypointLeafIsAt(this));
        Destroy(gameObject);
    }
Exemplo n.º 2
0
    // Kills the ant
    public void Die()
    {
        AntManager.main.RemoveAntFromList(this);
        if (previousWaypoint == null && targetWaypoint.GetComponent <Waypoint>() == null)
        {
            Destroy(gameObject);
            return;
        }

        GameObject trashGameObject = Instantiate(
            TrashManager.main.TrashPrefab(),
            gameObject.transform.position,
            new Quaternion(0, 0, 0, 0),
            TrashManager.main.gameObject.transform
            );

        Trash trash = trashGameObject.GetComponent <Trash>();

        if (antLevel == AntManager.SceneView.ABOVE_GROUND)
        {
            trash.SetLayer(Trash.Layer.SURFACE);
        }
        else
        {
            trash.SetLayer(Trash.Layer.UNDERGROUND);
        }
        TrashManager.main.CreatedNewTrash(trash);

        if (previousWaypoint == null)
        {
            TrashManager.main.AddTrashToWaypoints(trash, targetWaypoint.GetComponent <Waypoint>());
            trash.AssignOneWaypoint(targetWaypoint.GetComponent <Waypoint>());
        }
        else
        {
            float lastDistance   = Vector2.Distance(transform.position, previousWaypoint.transform.position);
            float targetDistance = Vector2.Distance(transform.position, targetWaypoint.transform.position);

            if (targetDistance < lastDistance)
            {
                TrashManager.main.AddTrashToWaypoints(trash, targetWaypoint.GetComponent <Waypoint>());
            }
            else
            {
                TrashManager.main.AddTrashToWaypoints(trash, previousWaypoint.GetComponent <Waypoint>());
            }

            trash.AssignConnectedWaypoint(targetWaypoint.GetComponent <Waypoint>(), previousWaypoint.GetComponent <Waypoint>());
            FlowManager.main.RemoveAntFromRoad(targetWaypoint.GetComponent <Waypoint>(), previousWaypoint.GetComponent <Waypoint>());
        }

        Destroy(gameObject);
    }