コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            GameManager.Instance.playerAttack[Random.Range(0, 3)].Play();
            spawnProjectile();
        }

        if (health <= 0)
        {
            Destroy(gameObject);
        }

        Vector2 current = rigidbody.position;

        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");

        var target = (new Vector2(x, y) * speed);

        Vector2 move = target * speed;
        Vector2 next = current + target * Time.fixedDeltaTime;

        renderer.SetSprite(move);
        rigidbody.MovePosition(next);
    }