Esempio n. 1
0
    public List <(int, int)> GetSuccessors()
    {
        List <(int, int)> successors = new List <(int, int)>();
        float             hit_len    = 1.0f;
        Ray fwd   = new Ray(transform.position, transform.forward);
        Ray bkwd  = new Ray(transform.position, -transform.forward);
        Ray right = new Ray(transform.position, transform.right);
        Ray left  = new Ray(transform.position, -transform.right);

        Ray[] directions = { fwd, bkwd, right, left };

        RaycastHit hit;

        foreach (Ray i in directions)
        {
            if (Physics.Raycast(i, out hit, hit_len))
            {
                GndController surrounding = hit.collider.gameObject.GetComponent <GndController>();
                if (surrounding.is_walkable)
                {
                    successors.Add(surrounding.GetCoordinate());
                }
            }
        }
        return(successors);
    }
Esempio n. 2
0
    private void Awake()
    {
        if (m_instance != null && m_instance != this)
        {
            Destroy(this.gameObject);
        }
        m_instance = this;

        gnds = GameObject.FindGameObjectsWithTag("Ground");
        grid = new GndController[length, width];
        foreach (GameObject gnd in gnds)
        {
            GndController gndController = gnd.GetComponent <GndController>();
            int           x             = gndController.GetCoordinate().Item1;
            int           y             = gndController.GetCoordinate().Item2;
            grid[x, y] = gndController;
        }
    }