- Home /
Player triggered cutscene with collider?
Ok this must be the simplest thing to implement ever, yet after trying to google my way to the answer, I am still at a loss. I am new to scripting, but I doubt it should ever be this hard to do this. What I basically want to do is have the player collide with a collider, which should then change the main player camera to a separate camera. I have seen many videos covering this to a degree, but they all seem to not explain fully what they are actually doing, or are doing things that are way more advanced than what I need. What would be the most basic way of going about this?
Player with collider touches box collider with isTrigger checked, player camera switches to cutscene camera?
Answer by Hellium · Oct 06, 2017 at 11:17 AM
Put the following script on the object holding the trigger your player must run into.
using UnityEngine;
[RequireComponent( typeof(Collider) )]
public class CutsceneTrigger : MonoBehaviour
{
public Camera playerCamera ; // Drag & Drop the camera of the player
public Camera cutsceneCamera ; // Drag & Drop the camera used for the cutscene
private void OnTriggerEnter( Collider other )
{
if( /* Make sure the `other` collider is your player */ )
{
playerCamera.enabled = false ;
cutsceneCamera.enabled = true;
}
}
}
Note : I haven't tested the script at all. Tell me if you have any error or if it does not work. Don't forget to make sure all the requirements to detect collisions are satisfied
Thank you for the quick response, and it seems like a very simple script to use. However, I am still confused as to what this "other" means? And not sure what to put inside the if statement parentheses.
If you take a closer look at the documentation, other
is the other collider involved in the collision, here, the collider of your player.
In the parenthesis, you can put something like if( other.CompareTag("Player") )
(Don't forget to tag your player accordingly)
Aha, I see! Alright, now my collider definitely triggers it, but I then get the text pop up "Display 1 No Cameras Rendering". What does this mean?