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 Transform xrRig; // Reference to the XR Rig's Transform
|
||||
private Vector3 initialPosition; // Store the initial position
|
||||
private Quaternion initialRotation; // Store the initial rotation
|
||||
private Vector3 initialPosition;
|
||||
private Quaternion initialRotation;
|
||||
|
||||
// Store the scene names for which you want to reset the XR Rig position
|
||||
public string[] sceneNames;
|
||||
|
||||
private void Start()
|
||||
void Start()
|
||||
{
|
||||
// Capture the initial position and rotation at the start of the scene
|
||||
initialPosition = xrRig.position;
|
||||
initialRotation = xrRig.rotation;
|
||||
|
||||
// Listen for scene changes and reset XR Rig's position on scene load
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
// Store initial position and rotation at the start
|
||||
initialPosition = transform.position;
|
||||
initialRotation = transform.rotation;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
public void ResetingPosition()
|
||||
{
|
||||
// Check if the scene we are loading matches any of the target scenes
|
||||
foreach (string sceneName in sceneNames)
|
||||
{
|
||||
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;
|
||||
// Reset the XR Rig to the stored position and rotation
|
||||
transform.position = initialPosition;
|
||||
transform.rotation = initialRotation;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,12 @@ public class GoToSchool : MonoBehaviour
|
|||
public Collider parkPondTrigger; // Assign in Inspector
|
||||
public Collider schoolTrigger; // Assign in Inspector
|
||||
|
||||
public ResetPosition xrRig;
|
||||
void Awake()
|
||||
{
|
||||
Debug.Log("IM AWAKE");
|
||||
gameManager = GameManager.Instance; // Reference to GameManager instance
|
||||
|
||||
Debug.Log("currentday: " + gameManager.currentDay);
|
||||
if (storyPanelUI == null)
|
||||
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
|
||||
|
||||
gameManager.IncrementDay(); // Now called *after* scene fully loads
|
||||
|
||||
xrRig.ResetingPosition();
|
||||
}
|
||||
|
||||
IEnumerator Fade(float startAlpha, float endAlpha, float duration)
|
||||
|
|
Loading…
Add table
Reference in a new issue