private void Shoot() { GameObject bulletClone = Instantiate(_bullet, _pistolBone.GetWorldPosition(GetComponent <PlayAnimations>()._rightArmSkeleton.transform), Quaternion.identity); Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - bulletClone.transform.position; direction.Normalize(); bulletClone.GetComponent <Rigidbody2D>().velocity = direction * _bulletSpeed; Quaternion bulletRotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + 90f); bulletClone.transform.rotation = bulletRotation; }
// Update is called once per frame void Update() { Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - _rootBone.GetWorldPosition(transform); diff.Normalize(); rotationZ = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; if (gameObject.GetComponent <SkeletonAnimation>().skeleton.FlipX != true) { _rootBone.rotation = rotationZ; } else { _rootBone.rotation = rotationOffset - rotationZ; } }