UNITY PLEASE
This commit is contained in:
parent
de44313b3e
commit
5ba2513fce
2 changed files with 15 additions and 32 deletions
|
@ -5,41 +5,20 @@ using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
public class ResetPosition : MonoBehaviour
|
public class ResetPosition : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Transform xrRig; // Reference to the XR Rig's Transform
|
private Vector3 initialPosition;
|
||||||
private Vector3 initialPosition; // Store the initial position
|
private Quaternion initialRotation;
|
||||||
private Quaternion initialRotation; // Store the initial rotation
|
|
||||||
|
|
||||||
// Store the scene names for which you want to reset the XR Rig position
|
void Start()
|
||||||
public string[] sceneNames;
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
{
|
||||||
// Capture the initial position and rotation at the start of the scene
|
// Store initial position and rotation at the start
|
||||||
initialPosition = xrRig.position;
|
initialPosition = transform.position;
|
||||||
initialRotation = xrRig.rotation;
|
initialRotation = transform.rotation;
|
||||||
|
|
||||||
// Listen for scene changes and reset XR Rig's position on scene load
|
|
||||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
public void ResetingPosition()
|
||||||
{
|
{
|
||||||
// Check if the scene we are loading matches any of the target scenes
|
// Reset the XR Rig to the stored position and rotation
|
||||||
foreach (string sceneName in sceneNames)
|
transform.position = initialPosition;
|
||||||
{
|
transform.rotation = initialRotation;
|
||||||
if (scene.name == sceneName)
|
|
||||||
{
|
|
||||||
// Reset XR Rig position and rotation to the original values
|
|
||||||
xrRig.position = initialPosition;
|
|
||||||
xrRig.rotation = initialRotation;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
// Remove the sceneLoaded listener when this object is destroyed
|
|
||||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,12 @@ public class GoToSchool : MonoBehaviour
|
||||||
public Collider parkPondTrigger; // Assign in Inspector
|
public Collider parkPondTrigger; // Assign in Inspector
|
||||||
public Collider schoolTrigger; // Assign in Inspector
|
public Collider schoolTrigger; // Assign in Inspector
|
||||||
|
|
||||||
|
public ResetPosition xrRig;
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
|
Debug.Log("IM AWAKE");
|
||||||
gameManager = GameManager.Instance; // Reference to GameManager instance
|
gameManager = GameManager.Instance; // Reference to GameManager instance
|
||||||
|
Debug.Log("currentday: " + gameManager.currentDay);
|
||||||
if (storyPanelUI == null)
|
if (storyPanelUI == null)
|
||||||
storyPanelUI = GameObject.Find("Story Panel"); // Use the exact name
|
storyPanelUI = GameObject.Find("Story Panel"); // Use the exact name
|
||||||
|
|
||||||
|
@ -131,6 +133,8 @@ public class GoToSchool : MonoBehaviour
|
||||||
yield return new WaitForSeconds(1f); // Small delay to ensure scene transition
|
yield return new WaitForSeconds(1f); // Small delay to ensure scene transition
|
||||||
|
|
||||||
gameManager.IncrementDay(); // Now called *after* scene fully loads
|
gameManager.IncrementDay(); // Now called *after* scene fully loads
|
||||||
|
|
||||||
|
xrRig.ResetingPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator Fade(float startAlpha, float endAlpha, float duration)
|
IEnumerator Fade(float startAlpha, float endAlpha, float duration)
|
||||||
|
|
Loading…
Add table
Reference in a new issue