Пример #1
0
    static void incrementWaypoint()
    {
        ctrWaypoint++;
        var gameObjects   = GameObject.FindGameObjectsWithTag("Waypoint");
        int totalWaypoint = gameObjects.Length;

        if (ctrWaypoint == totalWaypoint)
        {
            // Create Graph
            List <Waypoint> listWaypoint = new List <Waypoint>();
            foreach (var gameObject in gameObjects)
            {
                waypointController controller = gameObject.GetComponent <waypointController>();
                Waypoint           waypoint   = controller.waypoint;
                foreach (var waypointController in controller.waypointControllers)
                {
                    waypoint.waypoints.Add(waypointController.waypoint);
                }
                listWaypoint.Add(waypoint);
            }
            GraphWaypoint graph = new GraphWaypoint {
                waypoints = listWaypoint
            };
            waypointController.graph = graph;
            Debug.Log(listWaypoint.Count);
            // Spawn Enemy
            enemyController.initEnemies();
            // Remove GameObject
            foreach (var gameObject1 in gameObjects)
            {
                Destroy(gameObject1);

                /*gameObject1.GetComponent<SpriteRenderer>().sprite = null;
                 * gameObject1.GetComponent<CircleCollider2D>().enabled = false;*/
            }
        }
    }
Пример #2
0
    void check360()
    {
        // Check 360
        for (int deg = 0; deg < 360; deg++)
        {
            Vector2      direction    = new Vector2(Mathf.Sin(deg), Mathf.Cos(deg));
            Vector3      origin       = obj.GetComponent <Transform>().position + (Vector3)direction;
            RaycastHit2D raycastHit2D = Physics2D.Raycast(origin, direction, 15);
            if (raycastHit2D.collider == null)
            {
                // no hit
            }
            else
            {
                // hit object
                GameObject otherObj = raycastHit2D.collider.gameObject;
                if (otherObj.CompareTag("Waypoint"))
                {
                    waypointController objController = otherObj.GetComponent <waypointController>();
                    if (!waypointControllers.Contains(objController))
                    {
                        this.waypointControllers.Add(objController);
                        objController.waypointControllers.Add(this);
                    }
                }
            }
        }
        string str = "";

        foreach (var waypointController in waypointControllers)
        {
            str += waypointController.name + ", ";
        }
        Debug.Log($"{this.name}\n{str}");
        waypointController.incrementWaypoint();
    }