Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class DetectInteractable : UnityEngine.MonoBehaviour
- {
- public Camera cam;
- public float distanceToSee;
- public string objectHit;
- public bool interactableObject = false;
- public Transform parentToSearch;
- public Scaling scaling;
- public int spinX = 0;
- public int spinY = 0;
- public int spinZ = 0;
- public GameObject navi;
- public GameObject itemsDescriptionCanvas;
- public Text itemsDescriptionText;
- private RaycastHit whatObjectHit;
- private Transform[] childrenToSearch;
- private void Start()
- {
- childrenToSearch = parentToSearch.GetComponentsInChildren<Transform>();
- }
- private void Update()
- {
- if (cam.enabled == true)
- {
- if (Input.GetMouseButtonDown(0) && !scaling.scaleUp)
- {
- if (whatObjectHit.collider != null)
- ExecuteActions(whatObjectHit.collider.gameObject);
- }
- Debug.DrawRay(cam.transform.position, cam.transform.forward * distanceToSee, Color.magenta);
- if (Physics.Raycast(cam.transform.position, cam.transform.forward, out whatObjectHit, distanceToSee))
- {
- if (whatObjectHit.transform.tag == "Interactable")
- {
- objectHit = whatObjectHit.collider.gameObject.name;
- interactableObject = true;
- print("Hit ! " + whatObjectHit.collider.gameObject.name);
- if (scaling.objectToScale.transform.localScale == scaling.minSize)
- {
- scaling.objectToScale.transform.Rotate(spinX, spinY, spinZ);
- }
- ProcessItemsDescripations();
- itemsDescriptionCanvas.SetActive(true);
- }
- }
- else
- {
- if (scaling.objectToScale.transform.localScale == scaling.minSize)
- {
- navi.transform.rotation = new Quaternion(0, 0, 0, 0);
- }
- itemsDescriptionCanvas.SetActive(false);
- print("Not Hit !");
- }
- }
- }
- private void ExecuteActions(GameObject go)
- {
- var ia = go.GetComponent<ItemAction>();
- if (ia != null)
- {
- ia.ItemMove();
- }
- }
- void ProcessItemsDescripations()
- {
- foreach (Transform child in childrenToSearch)
- {
- if (child.GetComponent<ItemInformation>() != null)
- {
- ItemInformation iteminformation = child.GetComponent<ItemInformation>();
- if (child.name == objectHit)
- {
- itemsDescriptionText.text = iteminformation.description;
- }
- }
- }
- }
- public class ViewableObject : UnityEngine.MonoBehaviour
- {
- public string displayText;
- public bool isInteractable;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement