- Home /
How to make a "pressure sensor" of sorts that when rolled over switches to another scene
First of all, I've just started using Unity so I don't know quite how to explain what I am doing.
Anyways I've been making a game for a class at my school and I need to know how to change to "Level2" when I roll over a cube with a sphere.
Something like a "pressure sensor" maybe?
I thought I could do something with the Box Collider but I'm not quite sure how to do it. It would really help if someone knew of some code that would help with this. I'm using Javascript in my project.
The picture below shows the cube in the hole that I need to roll over. I just need to make it so when I roll over the cube it immediately switches to another scene titled "Level2"
Thanks in advance for any answer I might receive!
Sebastian
Answer by getyour411 · Apr 28, 2014 at 03:11 AM
Put a test cube in your scene mostly submerged below the terrain, attach a basic OnTriggerEnter that calls Application.LoadLevel on player entry; all these parts are well documented with many examples, doc, videos/tutorials, code snippets. Please try research and reading a bit, implement the basic parts in code and ask a new question if needed.
Alright, I'll try researching a bit. Thanks for the answer!
Answer by SteelArrow21 · Apr 28, 2014 at 03:20 AM
Ive got a script in C#, but you wont need to do any editing to the script so you can use it if you want. Make an empty game object with a collider slightly sticking above ground. Tag the player as "Player" and attach this script to the empty game object. (Name it "PressurePlate")
using UnityEngine;
using System.Collections;
public class PressurePlate : MonoBehaviour {
void OnTriggerEnter (Collider other){
if(other.tag == "Player")
Application.LoadLevel("Level2");
}
}
Hopefully there won't be errors. If there are, post them and I'll fix it.
Thank you so much! This really helps! I'll try it out when I get the chance and get back to you if I have any questions. Thanks again :)