public void FillInteractionPanel(Interactable interactableElement) { ClearInteractionContainer(); switch (interactableElement.interactionType) { case InteractionType.ChangeColor: foreach (Color c in interactableElement.availableColors) { InteractableOption io = Instantiate(optionPrefab, optionContainer).GetComponent <InteractableOption>(); io.optionButton.onClick.AddListener(() => interactableElement.ChangeColor(c)); io.optionImage.color = c; } break; case InteractionType.ChangeMaterial: foreach (Material m in interactableElement.availableMaterials) { InteractableOption io = Instantiate(optionPrefab, optionContainer).GetComponent <InteractableOption>(); Sprite s = Sprite.Create((Texture2D)m.GetTexture("_MainTex"), io.optionImage.sprite.rect, io.optionImage.sprite.pivot); io.optionButton.onClick.AddListener(() => interactableElement.ChangeMaterial(interactableElement.availableMaterials.IndexOf(m))); io.optionImage.sprite = s; io.optionImage.color = m.GetColor("_Color"); } break; case InteractionType.ChangeModel: break; } }
private void CheckForInteractables() { RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, minDisToHuman, interactableLayer)) { if (hit.collider.GetComponent <Interactable>() == null) { return; } lastSelectedInteractable = hit.collider.GetComponent <Interactable>(); lastSelectedInteractable.ChangeColor(true); if (Input.GetMouseButtonDown(0)) { lastSelectedInteractable.ActivateAction(); } } else if (lastSelectedInteractable != null) { lastSelectedInteractable.ChangeColor(false); lastSelectedInteractable = null; } }