Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ModelLimit : MonoBehaviour
- {
- Transform model;
- // Start is called before the first frame update
- void Start()
- {
- model = transform.GetChild(0);
- }
- // Update is called once per frame
- void Update()
- {
- Vector3 dir = Camera.main.transform.position - transform.position;
- Quaternion toCam = Quaternion.LookRotation(dir, transform.up);
- Quaternion inverse = Quaternion.Inverse(toCam);
- Vector3 rotation = inverse.eulerAngles;
- rotation /= 30f;
- rotation = new Vector3(Mathf.Round(rotation.x) * 30f, Mathf.Round(rotation.y), Mathf.Round(rotation.z) * 30f);
- model.rotation = toCam * Quaternion.Euler(rotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment