void MouseRaycast() { // check hit RaycastHit hit; if (Physics.Raycast(m_Camera.ScreenPointToRay(Input.mousePosition), out hit)) { // check mouse interactive item MouseInteractiveItem item = hit.transform.gameObject.GetComponent <MouseInteractiveItem> (); currentItem = item; // if current item exists, call Over if (currentItem && currentItem != lastItem) { currentItem.Over(); } // if it's not the same as the last item, deactivate the last item if (currentItem != lastItem) { DeactivateLastItem(); } lastItem = item; } else { // nothing was hit DeactivateLastItem(); currentItem = null; } }
void DeactivateLastItem() { if (lastItem == null) { return; } lastItem.Out(); lastItem = null; }