[FIXED] Help with Using Trigger to Move Scenes
Hi, I’m trying to make a “door” to another scene by using a cube with a trigger. I’ve researched several scripts for this and nothing seems to work! All of them were made over a year ago, the most recent being Jan. 2017. The one I’m using now is: using UnityEngine; using SystemCollections; using UnityEngine.SceneManagement;
public class MoveScene : MonoBehaviour
{
[SerializeField] private string loadLevel;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag(“Player”))
{
SceneManager.LoadScene(loadLevel);
}
}
}
Is there anything wrong with the code? Has Unity updated in some way that makes it obselete? If you have a new script for this, it would be greatly appreciated. Thanks!
The code is fine. Are you sure all the conditions for trigger detection are met?
https://unity3d.com/learn/tutorials/s/physics
Are you using 2D objects?
@Hellium I’m using 3D objects. I have the cube set to Is Trigger. The problem arises when I add the script. It says, “Please fix compile errors before creating new script components.” The only error I see is above the script and that error says, “No $$anonymous$$onoBehaviour scripts in the file, or their names do not match the file name.”
p.s. im new to this, thanks for your help :)
Answer by Hellium · Apr 09, 2018 at 10:03 AM
Please, follow carefully the Physics tutorials and make sure:
At least one of the two objects has a Rigidbody
Both objects have a Collider
The object holding your script has a Collider set to Trigger
The script you've provided in the question is named
MoveScene.cs
@Hellium thank you so much that last thing you said worked! Thank you one million times <3
Glad I helped.
Please, use the "Accept" button to indicate your problem has been resolved ins$$anonymous$$d of using a tag in your question's title.