LoginSignup
19
22

More than 5 years have passed since last update.

【Unity2D】Spriteを左右反転する方法

Last updated at Posted at 2014-05-13

001.png
Spriteの中心(Pivot)をCenterにしていれば、transform.localScale.xに負の値を代入することで、Spriteが左右反転します。

float x = Input.GetAxisRaw("Horizontal");
// デフォルトが右向きの画像の場合
// スケール値取り出し
Vector3 scale = transform.localScale;
if(x >= 0) {
  // 右方向に移動中
  scale.x = 1; // そのまま(右向き)
}
else {
  // 左方向に移動中
  scale.x = -1; // 反転する(左向き)
}
// 代入し直す
transform.localScale = scale;

19
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
22