Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- public class FloatingOrigin : MonoBehaviour {
- [Header("Settings")]
- [Tooltip("When Target's position reaches this magnitude/distance, Target and Scene Root transforms will be moved.")]
- public float _threshold = 1000f;
- [Header("References")]
- [Tooltip("This Transform we will use to calculate the distance from origin. It will be moved back to near origin.")]
- public Transform _target;
- void Awake() {
- if (_target == null)
- _target = Camera.main.transform;
- }
- void LateUpdate() {
- Vector3 targetPos = _target.position;
- targetPos.y = 0f;
- if (targetPos.magnitude > _threshold) {
- foreach (GameObject rootGO in SceneManager.GetActiveScene().GetRootGameObjects()) {
- rootGO.transform.position -= targetPos;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement