## 枪械旋转与翻转
public class ShouGun : MonoBehaviour
{
private Vector2 mousePos;
private Vector2 direction;
private float flipY;
// Start is called before the first frame update
void Start()
{
flipY = transform.localScale.y;
}
// Update is called once per frame
void Update()
{
Gunflip();
}
void Gunflip()
{
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//翻转功能
if (mousePos.x < transform.position.x)
{
transform.localScale = new Vector3(flipY, -flipY, 1);
}
else
{
transform.localScale = new Vector3(flipY, flipY, 1);
}
//朝向功能
direction = (mousePos - new Vector2(transform.position.x, transform.position.y)).normalized;
transform.right = direction;
}
}