Closed RabbitKazma closed 2 years ago
Rewrote code in ButtonHandler.cs to be non-hardcoded
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ButtonHandler : MonoBehaviour
{
public GameObject pointerOrigin;
private Ray _pointerRay;
private RaycastHit _hit;
private GameObject _hitObj;
private bool _doRaycast = false;
private void Update()
{
if (OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger)){
//if the right index trigger is pressed, set hit obj to null and do raycast
_hitObj = null;
_doRaycast = true;
}
else {
_doRaycast = false;
}
//hit obj handling
if (_hitObj != null && _hitObj.GetComponentInChildren<Button>() != null) {
char[] remove = { 'b', 't', 'n' };
SceneManager.LoadScene(_hit.collider.name.TrimStart(remove));
}
}
private void FixedUpdate()
{
if (_doRaycast)
{
//casting from the main camera to the point on screen where the mouse is
_pointerRay = new Ray(pointerOrigin.transform.position, pointerOrigin.transform.forward);
if (Physics.Raycast(_pointerRay, out _hit))
{
//if the point where the player click contains a gameobject
_hitObj = _hit.transform.gameObject;
}
}
}
}
Description: Buttons in the scene that change scenes should be named btnSCENENAME (e.g btnMyScene)
Button handling complete
@RabbitKazma please document the ButtonHandler.cs changes (code changes on fade transition) here
The scene now show the player's completion time
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class EndSceneTimer : MonoBehaviour
{
public TextMeshProUGUI txtTimer;
private void Start() {
txtTimer.text = $"Completed in {LessThanTen(PlayerPrefs.GetFloat("minutes"))}min {LessThanTen(Mathf.Round(PlayerPrefs.GetFloat("seconds")))}s";
PlayerPrefs.DeleteAll();
}
private string LessThanTen(float f) {
if(f < 10) {
return $"0{f}";
}
else {
return f.ToString();
}
}
}
Description: Script makes use of PlayerPrefs to keep track of the player's completion time
Rewrote code in ButtonHandler.cs to be non-hardcoded
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ButtonHandler : MonoBehaviour
{
public GameObject pointerOrigin;
public Animator transition;
private Ray _pointerRay;
private RaycastHit _hit;
private GameObject _hitObj;
private bool _doRaycast = false;
private float _timer = 0f;
private void Update()
{
if (OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger)){
//if the right index trigger is pressed, set hit obj to null and do raycast
_hitObj = null;
_doRaycast = true;
}
else {
_doRaycast = false;
}
//hit obj handling
if (_hitObj != null && _hitObj.GetComponentInChildren<Button>() != null) {
char[] remove = { 'b', 't', 'n' };
transition.SetTrigger("Fade");
_timer += Time.deltaTime;
if (_timer > 1)
{
SceneManager.LoadScene(_hit.collider.name.TrimStart(remove));
}
}
}
private void FixedUpdate()
{
if (_doRaycast)
{
//casting from the main camera to the point on screen where the mouse is
_pointerRay = new Ray(pointerOrigin.transform.position, pointerOrigin.transform.forward);
if (Physics.Raycast(_pointerRay, out _hit))
{
//if the point where the player click contains a gameobject
_hitObj = _hit.transform.gameObject;
}
}
}
}
Thanks @RabbitKazma, will close issue now
Completed start scene transition and from end scene back to start scene
Code + description
ButtonHandler.cs
Description:
Notes: