Example #1
0
    void Start()
    {
        //childGround 생성
        int     i, j;
        Vector2 vec = transform.position;

        childGround = new GameObject[sizeOfFieldWidth, sizeOfFieldHeight];
        navigator   = gameObject.AddComponent <FieldNavigation>();
        navigator.InitFieldNavigation(this);

        for (i = 0; i < sizeOfFieldWidth; i++)
        {
            for (j = 0; j < sizeOfFieldHeight; j++)
            {
                childGround[i, j]      = Instantiate(originOfChild, vec, transform.rotation, transform);
                childGround[i, j].name = fieldName;
                childGround[i, j].GetComponent <GroundUnit>().setIndex(i, j);
                navigator.AddNode(childGround[i, j].AddComponent <GroundNode>(), i, j);
                vec.y++;
            }
            vec.y = transform.position.y;
            vec.x++;
        }

        AccessPositionOfObject[] init = GameObject.FindGameObjectWithTag("Hall").GetComponentsInChildren <AccessPositionOfObject>();
        for (i = 0; i < init.Length; i++)
        {
            init[i].InitAccessGround();
        }
    }
Example #2
0
    public bool MoveThisGround(GameObject _targetGround)                  //이동 명령을 할 때 호출됨
    {
        if (_targetGround == null || !_targetGround.CompareTag("Ground")) //대상이 없거나 땅이 아니면 움직이지 않음
        {
            path.Clear();
            counter = -1;
            return(false);
        }

        targetGround = _targetGround;

        //출발좌표, 도착좌표를 받음
        targetPosition.x = _targetGround.transform.position.x;
        targetPosition.y = _targetGround.transform.position.y;
        thisPosition     = RayCastGround(transform.position).transform.position;

        FieldNavigation _navi = currentField.GetComponent <Field>().navigator;

        path = _navi.FindPath(RayCastGround(transform.position).GetComponent <GroundNode>(), _targetGround.GetComponent <GroundNode>());

        if (path != null)
        {
            counter  = path.Count - 1;
            isMoving = true;
            return(true);
        }

        return(false);
    }