Hi Tony,
My character can only face left & right, and the prefab has a isFacingLeft bool that controls the direction that the character is facing. It faces left by default
When entering a scene from the left, I would like my character to enter the scene facing right (isFacingLeft = false). What's your opinion on implementing this when using a ScenePortal?
ScenePortal and setting character facing direction in 2D game
Re: ScenePortal and setting character facing direction in 2D game
Hi,
Here's one way to do it:
1. Add information to the spawnpoint to specify the player should face left or right. For example, you could add tags "FaceLeft" and "FaceRight", or you could add a simple script:
2. Make a subclass of PositionSaver. Override ApplyData. Example using the SpawnpointDirection script above:
In your subclass, you could also save and restore the player's facing direction for use in saved games.
Here's one way to do it:
1. Add information to the spawnpoint to specify the player should face left or right. For example, you could add tags "FaceLeft" and "FaceRight", or you could add a simple script:
Code: Select all
public class SpawnpointDirection : MonoBehaviour
{
public bool faceLeft;
}
Code: Select all
public class CustomPlayerPositionSaver : PositionSaver
{
public override void ApplyData(string s)
{
if (usePlayerSpawnpoint && SaveSystem.playerSpawnpoint != null)
{
var spawnpointDirection = SaveSystem.playerSpawnpoint.GetComponent<SpawnpointDirection>();
if (spawnpointDirection != null)
{
GetComponent<YourCharacterScript>().isFacingLeft = spawnpointDirection.faceLeft;
}
}
base.ApplyData(s);
}
}
Re: ScenePortal and setting character facing direction in 2D game
That worked perfectly, thanks Tony!
Re: ScenePortal and setting character facing direction in 2D game
Awesome! Glad to help.