Skip to content
Snippets Groups Projects
BoundingPositioning.cs 823 B
Newer Older
  • Learn to ignore specific revisions
  • using UnityEngine;
    
    public class BoundingPositioning : MonoBehaviour
    {
        public Anker x = Anker.center;
        public Anker y = Anker.center;
        public Anker z = Anker.center;
    
        public MeshFilter mesh = null;
    
        public enum Anker
        {
            min = 0, center = 1, max = 2
        }
    
        private void OnValidate() => UpdatePosition();
    
        private void Start() => UpdatePosition();
    
    
        private void UpdatePosition()
        {
            if (mesh == null
             || mesh.sharedMesh == null)
                return;
    
            Vector3[] bounds = {
                mesh.sharedMesh.bounds.min,
                mesh.sharedMesh.bounds.center,
                mesh.sharedMesh.bounds.max,
            };
    
            transform.position = new Vector3(
    
    MaZiFAU's avatar
    MaZiFAU committed
                bounds[(int)x][0],
                bounds[(int)y][1],