예제 #1
0
    // Update is called once per frame
    void Update()
    {
        gold = GameObject.FindGameObjectWithTag("Gold").transform;
        if (waitTime <= 0)
        {
            var directionToEnemy = gold.transform.position - mobilePlayer.transform.position;

            Vector3 forward = mobilePlayer.transform.TransformDirection(Vector3.forward);
            Vector3 right   = mobilePlayer.transform.TransformDirection(Vector3.forward);

            var projectionUP    = Vector3.Dot(forward, directionToEnemy);
            var projectionRight = Vector3.Dot(right, directionToEnemy);

            if (projectionRight < 0)
            {
                mobilePlayer.LeftButtonPressed();
                waitTime = startWaitTime;
            }
            else
            {
                mobilePlayer.RightButtonPressed();
                waitTime = startWaitTime;
            }

            if (projectionUP < 0)
            {
                mobilePlayer.LeftButtonPressed();
                waitTime = startWaitTime;
            }
            else
            {
                mobilePlayer.StraightButtonPressed();
                waitTime = startWaitTime;
            }
        }
        else
        {
            waitTime -= Time.deltaTime;
        }
    }
예제 #2
0
    private void ButtonPressed(Node current, Node Next)
    {
        direction = playercontroller.direction;
        switch (direction)
        {
        case PlayerDirection.UP:
        {
            if (current.arrayPosition.x - 1 == Next.arrayPosition.x)
            {
                playercontroller.LeftButtonPressed();
            }
            else if (current.arrayPosition.x + 1 == Next.arrayPosition.x)
            {
                playercontroller.RightButtonPressed();
            }
            else if (current.arrayPosition.y + 1 == Next.arrayPosition.y)
            {
                playercontroller.StraightButtonPressed();
            }
            else
            {
                ReGenPath();
                if (TargetGold)
                {
                    findNewRandomPath();
                    TargetGold = false;
                }
            }
        }
        break;

        case PlayerDirection.LEFT:
        {
            if (current.arrayPosition.x + 1 == Next.arrayPosition.x)
            {
                playercontroller.StraightButtonPressed();
            }
            else if (current.arrayPosition.y - 1 == Next.arrayPosition.y)
            {
                playercontroller.LeftButtonPressed();
            }
            else if (current.arrayPosition.y + 1 == Next.arrayPosition.y)
            {
                playercontroller.RightButtonPressed();
            }
            else
            {
                ReGenPath();
                if (TargetGold)
                {
                    findNewRandomPath();
                    TargetGold = false;
                }
            }
        }
        break;

        case PlayerDirection.RIGHT:
        {
            if (current.arrayPosition.x - 1 == Next.arrayPosition.x)
            {
                playercontroller.StraightButtonPressed();
            }
            else if (current.arrayPosition.y + 1 == Next.arrayPosition.y)
            {
                playercontroller.LeftButtonPressed();
            }
            else if (current.arrayPosition.y - 1 == Next.arrayPosition.y)
            {
                playercontroller.RightButtonPressed();
            }
            else
            {
                ReGenPath();
                if (TargetGold)
                {
                    findNewRandomPath();
                    TargetGold = false;
                }
            }
        }
        break;

        case PlayerDirection.DOWN:
        {
            if (current.arrayPosition.x - 1 == Next.arrayPosition.x)
            {
                playercontroller.LeftButtonPressed();
            }
            else if (current.arrayPosition.x + 1 == Next.arrayPosition.x)
            {
                playercontroller.RightButtonPressed();
            }
            else if (current.arrayPosition.y - 1 == Next.arrayPosition.y)
            {
                playercontroller.StraightButtonPressed();
            }
            else
            {
                ReGenPath();
                if (TargetGold)
                {
                    findNewRandomPath();
                    TargetGold = false;
                }
            }
        }
        break;
        }
    }