23 lines
735 B
C#
23 lines
735 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class BackgroundMoveableCharacter : MovableObject
|
|
{
|
|
public bool defaultFacingRight = true; // 该角色默认朝向是否向右
|
|
|
|
protected override void Initialize()
|
|
{
|
|
AdjustFacingDirection();
|
|
}
|
|
|
|
private void AdjustFacingDirection()
|
|
{
|
|
// 如果生成在左边,朝向右;如果生成在右边,朝向左
|
|
bool movingRight = transform.position.x < 0;
|
|
bool shouldFlip = (defaultFacingRight && !movingRight) || (!defaultFacingRight && movingRight);
|
|
transform.localScale = new Vector3(shouldFlip ? -1 : 1, 1, 1);
|
|
direction = movingRight ? Vector2.right : Vector2.left;
|
|
}
|
|
}
|