예제 #1
0
    IEnumerator moveToPoint()
    {
        while (true)
        {
            switch (nowPoint)
            {
            case checkPoint.point1:

                while (nowPoint == checkPoint.point1)
                {
                    if (transform.position.y == limitPoint1.y)
                    {
                        nowPoint = checkPoint.point2;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, firstPoint, createEnmey.enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;

            case checkPoint.point2:
                while (nowPoint == checkPoint.point2)
                {
                    if (transform.position.x == limitPoint2.x)
                    {
                        nowPoint = checkPoint.point3;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, secondPoint, createEnmey.enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;

            case checkPoint.point3:
                while (nowPoint == checkPoint.point3)
                {
                    if (transform.position.y == limitPoint2.y)
                    {
                        nowPoint = checkPoint.point4;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, finalPoint, createEnmey.enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;

            case checkPoint.point4:
                while (nowPoint == checkPoint.point4)
                {
                    if (transform.position.x == limitPoint1.x)
                    {
                        nowPoint = checkPoint.point1;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, startPoint, createEnmey.enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;
            }
        }
    }
예제 #2
0
    //스프라이트 변경


    // Start is called before the first frame update
    void Start()
    {
        nowPoint = checkPoint.point1;
        //리미트포인트 1은 좌상단 2는 우하단
        startPoint         = new Vector2(limitPoint1.x, limitPoint2.y);
        firstPoint         = new Vector2(limitPoint1.x, limitPoint1.y);
        secondPoint        = new Vector2(limitPoint2.x, limitPoint1.y);
        finalPoint         = new Vector2(limitPoint2.x, limitPoint2.y);
        transform.position = startPoint;



        StartCoroutine(moveToPoint());
    }
예제 #3
0
 void OnTriggerStay(Collider col)
 {
     state = checkPoint.start;
 }
예제 #4
0
    IEnumerator moveToPoint()
    {
        //리미트포인트 1은 좌상단 2는 우하단
        Vector2 startPoint  = new Vector2(limitPoint1.x, limitPoint2.y);
        Vector2 firstPoint  = new Vector2(limitPoint1.x, limitPoint1.y);
        Vector2 secondPoint = new Vector2(limitPoint2.x, limitPoint1.y);
        Vector2 finalPoint  = new Vector2(limitPoint2.x, limitPoint2.y);


        transform.position = startPoint;

        while (true)
        {
            switch (nowPoint)
            {
            case checkPoint.point1:

                while (nowPoint == checkPoint.point1)
                {
                    if (transform.position.y == limitPoint1.y)
                    {
                        nowPoint = checkPoint.point2;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, firstPoint, enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;

            case checkPoint.point2:
                while (nowPoint == checkPoint.point2)
                {
                    if (transform.position.x == limitPoint2.x)
                    {
                        nowPoint = checkPoint.point3;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, secondPoint, enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;

            case checkPoint.point3:
                while (nowPoint == checkPoint.point3)
                {
                    if (transform.position.y == limitPoint2.y)
                    {
                        nowPoint = checkPoint.point4;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, finalPoint, enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;

            case checkPoint.point4:
                while (nowPoint == checkPoint.point4)
                {
                    if (transform.position.x == limitPoint1.x)
                    {
                        nowPoint = checkPoint.point1;
                    }
                    transform.position = Vector2.MoveTowards(transform.position, startPoint, enemySpeed * Time.deltaTime);
                    yield return(null);
                }
                break;
            }
        }

        yield return(null);
    }
예제 #5
0
 // Start is called before the first frame update
 void Start()
 {
     nowPoint = checkPoint.point1;
     StartCoroutine(moveToPoint());
 }
예제 #6
0
 public void setCheckPointPlayer(checkPoint get)
 {
     actualCheckPoint = get;
 }
예제 #7
0
 // Start is called before the first frame update
 void Start()
 {
     check = FindObjectOfType<checkPoint>();
 }