I have a script to position the player where fell off from the platform.
Platform Tracker.cs
public GameObject platformTrackerPoint;
public Vector3 platformTransform;
public PlayerMovement thePlayerMovement;
void Start()
{
platformTrackerPoint = GameObject.Find("PlatformTrackerPoint");
thePlayerMovement = FindObjectOfType<PlayerMovement>();
}
void Update()
{
if ((transform.position.x < platformTrackerPoint.transform.position.x) && thePlayerMovement.grounded)
{
platformTransform = gameObject.transform.position;
Debug.Log ("Plaform Transform =" + platformTransform);
}
}
As I debugged, platformTransform shows the value I need. But its not reflecting in the code below.
GameController.cs
public PlatformTracker thePlatformTracker;
public Vector3 tempPosition;
void Start () {
platformStartPoint = platformGenerator.position;
playerStartPoint = thePlayer.transform.position;
thePlatformTracker = FindObjectOfType<PlatformTracker>();
thePlayer = FindObjectOfType<PlayerMovement>();
}
public void RespawnPlayer()
{
thePlayer.transform.position = thePlatformTracker.platformTransform;
}
Your help is much appreciated. Please let me know if anything is not clear.