コード例 #1
0
ファイル: PlayerShooter.cs プロジェクト: OcarinhaOfTime/DJMan
    private void Update()
    {
        Vector2 dir    = Vector2.right * playerPhy.facingSign;
        Vector2 aimDir = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

        angle = Vector2.SignedAngle(Vector2.right, dir);
        if (aimDir.magnitude > .1f)
        {
            angle = Vector2.SignedAngle(Vector2.right, aimDir);
            //angle = Mathf.Repeat(angle, 360);
            angle = (int)(angle / 45);
            angle = angle * 45;
        }

        if (Input.GetButtonDown("Fire1") && timer > fireRate)
        {
            timer = 0;
            var proj = pool.GetPoolable();
            proj.transform.position = (Vector2)shootPos + playerPhy.deltaVelocity;
            proj.gameObject.SetActive(true);
            Vector2 projDir = Quaternion.Euler(0, 0, angle) * Vector2.right;
            proj.Launch(projDir + Vector2.Scale(playerPhy.deltaVelocity, Vector2.right));
            audioSource.Play();
        }

        arrow.rotation   = Quaternion.Euler(0, 0, angle);
        arrow.localScale = new Vector3(playerPhy.facingSign, 1, 1);

        timer += Time.deltaTime;
    }