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 LayerMask layermask;
public int spinX = 0;
public int spinY = 0;
public int spinZ = 0;
public GameObject navi;
private RaycastHit whatObjectHit;
private bool clickForDescription = false;
private void Update()
{
if (Input.GetMouseButtonDown(0) && !scaling.scaleUp)
{
clickForDescription = true;
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, layermask.value)) //layerMask))
{
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);
}
clickForDescription = true;
}
else
{
if (scaling.objectToScale.transform.localScale == scaling.minSize)
{
navi.transform.rotation = new Quaternion(0, 0, 0, 0);
}
clickForDescription = false;
print("Not Hit !");
}
}
private void ExecuteActions(GameObject go)
{
var ia = go.GetComponent<ItemAction>();
if (ia != null)
{
ia.ItemMove();
}
}
private void OnGUI()
{
if (clickForDescription == true)
{
ProcessOnGUI(parentToSearch);
clickForDescription = false;
}
}
void ProcessOnGUI(Transform parent, int level = 0)
{
foreach (Transform child in parent)
{
if (child.GetComponent<ItemInformation>() != null)
{
ItemInformation iteminformation = child.GetComponent<ItemInformation>();
if (child.name == objectHit)
{
var centeredStyle = GUI.skin.GetStyle("Label");
centeredStyle.alignment = TextAnchor.UpperCenter;
GUI.Box(new Rect(
Screen.width / 2 /*- 50 + 20 * level*/, // <== INDENTATION
Screen.height / 2 ,100,50),/*- 25, 100, 50),*/
iteminformation.description, centeredStyle);
}
}
// Process next deeper level
ProcessOnGUI(child, level + 1);
}
}
public class ViewableObject : UnityEngine.MonoBehaviour
{
public string displayText;
public bool isInteractable;
}
}
Доходит до этой строки, используя точку останова:
GUI.Box(new Rect(
И есть описание объекта, который был поражен.
Но при запуске игры и этодобраться до части коробки ничего не показывает.Нет никаких исключений / с, это просто не показывает коробку.
Часть с оригиналом GUI.Box была такой, но ничего не показывала:
GUI.Box(new Rect(
Screen.width / 2 - 50 + 20 * level, // <== INDENTATION
Screen.height / 2 - 25, 100, 50),
iteminformation.description, centeredStyle);