VR/Assets/MyHead.cs

35 lines
750 B
C#
Raw Permalink Normal View History

2024-01-07 11:14:29 +01:00
using UnityEngine;
2024-01-07 13:00:44 +01:00
using UnityEngine.SceneManagement;
2024-01-07 13:01:21 +01:00
2024-01-07 11:14:29 +01:00
2024-01-07 13:37:25 +01:00
public class MyHead : MonoBehaviour
2024-01-07 11:14:29 +01:00
{
2024-01-07 13:37:25 +01:00
public Transform target; // The OVRCameraRig transform
void Update()
{
if (target != null)
{
// Set the position of this object to follow the OVRCameraRig
transform.position = target.position;
}
}
2024-01-07 11:14:29 +01:00
// This method is called when a collision occurs
2024-01-07 12:36:39 +01:00
2024-01-07 13:37:25 +01:00
// for the unfortunate event that a bullet hits the head collider
2024-01-07 11:14:29 +01:00
private void OnCollisionEnter(Collision collision)
{
// Check if the collision is with the specific object you want
if (collision.gameObject.CompareTag("Bullet"))
{
2024-01-07 13:00:44 +01:00
SceneManager.LoadScene("AfterLife");
2024-01-07 11:14:29 +01:00
}
}
2024-01-07 12:36:39 +01:00
2024-01-07 11:14:29 +01:00
}