using System.Collections; using UnityEngine; using Valve.VR.InteractionSystem; public class Catalog : MonoBehaviour { private Player player = null; public int maxShownObjects = 5; public int angle = 180; public float distance = .5f; public float objectScale = .1f; // Start is called before the first frame update void Start() { player = Player.instance; if (player == null) { Debug.LogError("[SteamVR Interaction] Teleport: No Player instance found in map.", this); Destroy(this.gameObject); return; } ShowCatalog(); } // Update is called once per frame void Update() { } private void ShowCatalog() { gameObject.transform.SetParent(player.hands[0].transform); gameObject.transform.localPosition = Vector3.zero; float radians = angle * Mathf.Deg2Rad; float angleIncrement = radians / (maxShownObjects - 1); for (float i = 0 / 2; i < maxShownObjects; i++) { var j = i * angleIncrement - radians / 2; var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.parent = transform; sphere.transform.localScale = Vector3.one * objectScale; sphere.transform.localPosition = new Vector3(Mathf.Sin(j), 0, Mathf.Cos(j)) * distance; } StartCoroutine(CatalogCoroutine()); } private IEnumerator CatalogCoroutine() { var hand = player.hands; while (true) { transform.rotation = Quaternion.RotateTowards(transform.rotation, player.hmdTransform.rotation, 380); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z); yield return null; } } private void OnDrawGizmosSelected() { float radians = angle * Mathf.Deg2Rad; float angleIncrement = radians / (maxShownObjects - 1); for (float i = 0 / 2; i < maxShownObjects; i++) { var j = i * angleIncrement - radians / 2; Gizmos.DrawWireSphere(transform.position + new Vector3(Mathf.Sin(j), 0, Mathf.Cos(j)) * distance, objectScale / 2); } } }