game: commenting infocollector and applying
This commit is contained in:
parent
6dadb918d1
commit
671e00943e
3 changed files with 58 additions and 22 deletions
|
@ -70787,27 +70787,27 @@ PrefabInstance:
|
|||
objectReference: {fileID: 2105633704}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 0.24471709
|
||||
value: 0.3312246
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 0.24471709
|
||||
value: 0.3312246
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 0.24471712
|
||||
value: 0.33122462
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -4.5748
|
||||
value: -4.587601
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 2.725
|
||||
value: 2.736999
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 3.3869
|
||||
value: 3.3354633
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
|
@ -146123,27 +146123,27 @@ PrefabInstance:
|
|||
objectReference: {fileID: 1425780483}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 0.24471712
|
||||
value: 0.33122462
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 0.24471714
|
||||
value: 0.33122465
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 0.24471712
|
||||
value: 0.33122462
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -4.510803
|
||||
value: -4.501
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 2.725
|
||||
value: 2.737
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 3.4943666
|
||||
value: 3.481
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8720035115758566761, guid: 115e0f30c5ec185489b02437aec67077, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
|
|
|
@ -11,36 +11,61 @@ using TMPro;
|
|||
|
||||
public class InfoCollector : MonoBehaviour
|
||||
{
|
||||
public float detectionRange = 2f; // Adjust for accurate VR detection
|
||||
public float gazeTimeRequired = 2f; // Time the player must look at the object before collecting info
|
||||
public float displayTime = 5f; // How long the info stays on screen
|
||||
public TMP_Text infoText; // UI Text (TextMeshPro)
|
||||
|
||||
// Defines the range to "view" the object to collect information
|
||||
public float detectionRange = 2f;
|
||||
|
||||
// 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;
|
||||
|
||||
// Defines whether UI is displaying to prevent spamming
|
||||
private bool isDisplaying = false;
|
||||
|
||||
// Defines the object the player is currently looking at
|
||||
private GameObject currentObject = null;
|
||||
|
||||
// Tracks how long the player has been looking at the object
|
||||
private float gazeTimer = 0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Assigns to player's camera
|
||||
vrCamera = Camera.main;
|
||||
infoText.text = ""; // Clear text initially
|
||||
|
||||
// Clear UI text initially
|
||||
infoText.text = "";
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Detects the direction the player is looking at
|
||||
Ray ray = new Ray(vrCamera.transform.position, vrCamera.transform.forward);
|
||||
RaycastHit hit;
|
||||
|
||||
// Stores data of object hit in the detection range
|
||||
if (Physics.Raycast(ray, out hit, detectionRange))
|
||||
{
|
||||
// Ensures that relevant info objects are detected
|
||||
if (hit.collider.CompareTag("InfoObject"))
|
||||
{
|
||||
// If the player is still looking at the same object, the gaze time
|
||||
if (currentObject == hit.collider.gameObject)
|
||||
{
|
||||
// Increases gaze time
|
||||
gazeTimer += Time.deltaTime;
|
||||
|
||||
// If gaze time reaches required time and is not displaying yet, display the information
|
||||
if (gazeTimer >= gazeTimeRequired && !isDisplaying)
|
||||
{
|
||||
// Display object information
|
||||
CollectInfo(currentObject);
|
||||
}
|
||||
}
|
||||
|
@ -60,28 +85,38 @@ public class InfoCollector : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
// Function to display object information
|
||||
void CollectInfo(GameObject obj)
|
||||
{
|
||||
// Prevents spamming of display
|
||||
isDisplaying = true;
|
||||
|
||||
// Displays information
|
||||
infoText.text = "Info Collected: " + obj.name + "\n" + GetObjectInfo(obj);
|
||||
Debug.Log("Collected information from: " + obj.name);
|
||||
|
||||
// Hide text after displayTime
|
||||
// Clears text after displayed time
|
||||
Invoke(nameof(ClearText), displayTime);
|
||||
}
|
||||
|
||||
// Function to clear text after a delay
|
||||
void ClearText()
|
||||
{
|
||||
// Removes text
|
||||
infoText.text = "";
|
||||
|
||||
// Allows new information to be displayed
|
||||
isDisplaying = false;
|
||||
}
|
||||
|
||||
string GetObjectInfo(GameObject obj)
|
||||
{
|
||||
// Define object descriptions here
|
||||
if (obj.name == "Info")
|
||||
// Check if the object's name is the same
|
||||
if (obj.CompareTag("Needles"))
|
||||
// Returns predefined information
|
||||
return "Test";
|
||||
|
||||
|
||||
// Default information if there is no specific case
|
||||
return "An unknown object with mysterious origins.";
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ TagManager:
|
|||
- Destroyable
|
||||
- Info
|
||||
- InfoObject
|
||||
- Bottle
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
|
Loading…
Add table
Reference in a new issue