void Awake() { t = target.GetIComponent <IDescriptiveText>(); if (t == null) { print("Error here! Should've been an IDescriptiveText, but there was none"); } }
void Update() { raycastColliders.RemoveAll(c => c == null); if (raycastColliders.Count == 0) { return; } raycastColliders.Sort( (one, two) => (one.transform.position - transform.position).sqrMagnitude.CompareTo( (two.transform.position - transform.position).sqrMagnitude) ); Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit = new RaycastHit(); //Compiler pleasing, the uses of hit will never happen without it being set for (int i = 0; i < raycastColliders.Count; i++) { if (raycastColliders[i].Raycast(ray, out hit, maxDistance)) { break; } if (i == raycastColliders.Count - 1) { //No hit toShow = ""; SetHoveredTransform(null); return; } } SetHoveredTransform(hit.transform); IDescriptiveText desc = hit.transform.GetIComponent <IDescriptiveText>(); if (desc != null) { toShow = desc.text; } hit.transform.SendMessage("OnActivatorHover", player, SendMessageOptions.DontRequireReceiver); if (Input.GetButtonDown(Co.ACTIVATE)) { hit.transform.SendMessage("OnActivate", player); } }