game: commenting infocollector and applying

This commit is contained in:
rezazfn 2025-02-07 14:37:22 +08:00
parent 6dadb918d1
commit 671e00943e
3 changed files with 58 additions and 22 deletions

View file

@ -70787,27 +70787,27 @@ PrefabInstance:
objectReference: {fileID: 2105633704} objectReference: {fileID: 2105633704}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalScale.x propertyPath: m_LocalScale.x
value: 0.24471709 value: 0.3312246
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalScale.y propertyPath: m_LocalScale.y
value: 0.24471709 value: 0.3312246
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalScale.z propertyPath: m_LocalScale.z
value: 0.24471712 value: 0.33122462
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: -4.5748 value: -4.587601
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 2.725 value: 2.736999
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 3.3869 value: 3.3354633
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
@ -146123,27 +146123,27 @@ PrefabInstance:
objectReference: {fileID: 1425780483} objectReference: {fileID: 1425780483}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalScale.x propertyPath: m_LocalScale.x
value: 0.24471712 value: 0.33122462
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalScale.y propertyPath: m_LocalScale.y
value: 0.24471714 value: 0.33122465
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalScale.z propertyPath: m_LocalScale.z
value: 0.24471712 value: 0.33122462
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: -4.510803 value: -4.501
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 2.725 value: 2.737
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 3.4943666 value: 3.481
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3} - target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w

View file

@ -11,36 +11,61 @@ using TMPro;
public class InfoCollector : MonoBehaviour public class InfoCollector : MonoBehaviour
{ {
public float detectionRange = 2f; // Adjust for accurate VR detection // Defines the range to "view" the object to collect information
public float gazeTimeRequired = 2f; // Time the player must look at the object before collecting info public float detectionRange = 2f;
public float displayTime = 5f; // How long the info stays on screen
public TMP_Text infoText; // UI Text (TextMeshPro)
// Defines how long the player must look at the object for to collect information
public float gazeTimeRequired = 2f;
// Defines how long the information UI will remain on screen
public float displayTime = 5f;
// Defines the UI text to display
public TMP_Text infoText;
// Defines the camera
private Camera vrCamera; private Camera vrCamera;
// Defines whether UI is displaying to prevent spamming
private bool isDisplaying = false; private bool isDisplaying = false;
// Defines the object the player is currently looking at
private GameObject currentObject = null; private GameObject currentObject = null;
// Tracks how long the player has been looking at the object
private float gazeTimer = 0f; private float gazeTimer = 0f;
void Start() void Start()
{ {
// Assigns to player's camera
vrCamera = Camera.main; vrCamera = Camera.main;
infoText.text = ""; // Clear text initially
// Clear UI text initially
infoText.text = "";
} }
void Update() void Update()
{ {
// Detects the direction the player is looking at
Ray ray = new Ray(vrCamera.transform.position, vrCamera.transform.forward); Ray ray = new Ray(vrCamera.transform.position, vrCamera.transform.forward);
RaycastHit hit; RaycastHit hit;
// Stores data of object hit in the detection range
if (Physics.Raycast(ray, out hit, detectionRange)) if (Physics.Raycast(ray, out hit, detectionRange))
{ {
// Ensures that relevant info objects are detected
if (hit.collider.CompareTag("InfoObject")) if (hit.collider.CompareTag("InfoObject"))
{ {
// If the player is still looking at the same object, the gaze time
if (currentObject == hit.collider.gameObject) if (currentObject == hit.collider.gameObject)
{ {
// Increases gaze time
gazeTimer += Time.deltaTime; gazeTimer += Time.deltaTime;
// If gaze time reaches required time and is not displaying yet, display the information
if (gazeTimer >= gazeTimeRequired && !isDisplaying) if (gazeTimer >= gazeTimeRequired && !isDisplaying)
{ {
// Display object information
CollectInfo(currentObject); CollectInfo(currentObject);
} }
} }
@ -60,28 +85,38 @@ public class InfoCollector : MonoBehaviour
} }
} }
// Function to display object information
void CollectInfo(GameObject obj) void CollectInfo(GameObject obj)
{ {
// Prevents spamming of display
isDisplaying = true; isDisplaying = true;
// Displays information
infoText.text = "Info Collected: " + obj.name + "\n" + GetObjectInfo(obj); infoText.text = "Info Collected: " + obj.name + "\n" + GetObjectInfo(obj);
Debug.Log("Collected information from: " + obj.name); Debug.Log("Collected information from: " + obj.name);
// Hide text after displayTime // Clears text after displayed time
Invoke(nameof(ClearText), displayTime); Invoke(nameof(ClearText), displayTime);
} }
// Function to clear text after a delay
void ClearText() void ClearText()
{ {
// Removes text
infoText.text = ""; infoText.text = "";
// Allows new information to be displayed
isDisplaying = false; isDisplaying = false;
} }
string GetObjectInfo(GameObject obj) string GetObjectInfo(GameObject obj)
{ {
// Define object descriptions here // Check if the object's name is the same
if (obj.name == "Info") if (obj.CompareTag("Needles"))
// Returns predefined information
return "Test"; return "Test";
// Default information if there is no specific case
return "An unknown object with mysterious origins."; return "An unknown object with mysterious origins.";
} }
} }

View file

@ -9,6 +9,7 @@ TagManager:
- Destroyable - Destroyable
- Info - Info
- InfoObject - InfoObject
- Bottle
layers: layers:
- Default - Default
- TransparentFX - TransparentFX