rabidus-test/Assets/Amazing Assets/Curved World/Example Scenes/Files/Scripts/TransformDynamicPosition.cs

42 lines
1.0 KiB
C#
Raw Normal View History

2023-10-02 19:12:35 +03:00
using UnityEngine;
namespace AmazingAssets.CurvedWorld.Example
{
[ExecuteAlways]
public class TransformDynamicPosition : MonoBehaviour
{
public CurvedWorld.CurvedWorldController curvedWorldController;
public Transform parent;
public Vector3 offset;
public bool recalculateRotation;
void Start()
{
if (parent == null)
parent = transform.parent;
}
void Update()
{
if (parent == null || curvedWorldController == null)
{
//Do nothing
}
else
{
//Transform position
transform.position = curvedWorldController.TransformPosition(parent.position + offset);
//Transform normal (calcualte rotation)
if (recalculateRotation)
transform.rotation = curvedWorldController.TransformRotation(parent.position + offset, parent.forward, parent.right);
}
}
}
}