Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float y = Input.GetAxisRaw("Vertical");

        if (x == 0 && y == 0)
        {
            return;
        }
        Mortion.moveDirection(x, y);
        Vector2 direction;

        if (Input.GetKey(KeyCode.RightArrow))
        {
            direction = new Vector2(1f, 0);
            movePlayer(direction);
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            direction = new Vector2(-1f, 0);
            movePlayer(direction);
        }
        if (Input.GetKey(KeyCode.UpArrow))
        {
            direction = new Vector2(0, 1f);
            movePlayer(direction);
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            direction = new Vector2(0, -1f);
            movePlayer(direction);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float y = Input.GetAxisRaw("Vertical");

        Mortion.moveDirection(x, y);

        // 一定時間ごとにプレイヤーに近づく
        currentTime += Time.deltaTime;
        if (currentTime > spanTime)
        {
            currentTime = 0f;
            Vector2 playerPosition = player.transform.position;
            // 難易度で敵の速度変更
            if (StartGameController.getDifficulty() == 2)
            {
                transform.position = Vector2.MoveTowards(transform.position, playerPosition, 3);
            }
            else
            {
                transform.position = Vector2.MoveTowards(transform.position, playerPosition, 1);
            }
        }
    }