Closed RotX18 closed 2 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EndSceneTransition : MonoBehaviour
{
private void OnCollisionEnter(Collision collision) {
if(collision.collider.CompareTag("Player")){
//if the colliding object has the tag of Player, load the end scene
SceneManager.LoadScene("EndScene");
}
}
}
Description:
Implemented a foreach loop to check for the number of completed puzzles with the total number of puzzles in the scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EndSceneTransition : MonoBehaviour
{
private int _completedPuzzles = 0;
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag("Player")){
//if the colliding object has the tag of Player
foreach(GameObject ele in GameManager.i.puzzles){
//for every element in the puzzles array
if (ele.GetComponent<IPuzzle>().Completed){
//if the current puzzle is completed
_completedPuzzles++;
}
}
if (_completedPuzzles == GameManager.i.puzzles.Length){
//if the number of completed puzzles = the total number of puzzles, load the end scene
SceneManager.LoadScene("EndScene");
}
else{
//else, reset the completed count
_completedPuzzles = 0;
}
}
}
}
Edits:
@RabbitKazma please document the fade transition code changes in EndSceneTransition.cs here
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;
}
}
}
}
Edits:
Thanks @RabbitKazma, will close issue now
Objective: When the player completes the game, have theem walk into an object that uses OnCollisionEnter(Collision collision) to transition to the end scene
Feature should: