madalaski

ModelLimit.cs

Jan 23rd, 2021
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ModelLimit : MonoBehaviour
  6. {
  7.     Transform model;
  8.  
  9.     // Start is called before the first frame update
  10.     void Start()
  11.     {
  12.         model = transform.GetChild(0);
  13.     }
  14.  
  15.     // Update is called once per frame
  16.     void Update()
  17.     {
  18.         Vector3 dir = Camera.main.transform.position - transform.position;
  19.         Quaternion toCam = Quaternion.LookRotation(dir, transform.up);
  20.         Quaternion inverse = Quaternion.Inverse(toCam);
  21.         Vector3 rotation = inverse.eulerAngles;
  22.         rotation /= 30f;
  23.         rotation = new Vector3(Mathf.Round(rotation.x) * 30f, Mathf.Round(rotation.y), Mathf.Round(rotation.z) * 30f);
  24.        
  25.         model.rotation = toCam * Quaternion.Euler(rotation);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment