通过2D物体尺寸 x轴乘以-(负号)
void Flip ()
{
// Switch the way the player is labelled as facing.转变朝向标签
facingRight = !facingRight;
// Multiply the player's x local scale by -1.尺寸x轴乘以`-(负号)`
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
Unity翻转角色方向
本文介绍了一种在Unity中实现2D角色翻转的方法。通过修改角色本地缩放的X轴值来达到视觉上的左右翻转效果。此方法适用于游戏开发中需要角色面向不同方向的情况。
1万+





