- Home /
How to make a key to a portal ?
Hello, I'm Lucas and I'm working in a Unity Game, it's almost ready, I just need to put some textures AND add this "key" to the portals... I'll explain:
After the player solve the level puzzle, he'll get into a portal (the portal is just a cube with a different texture), since the game is simple and I'm very new to unity and to java and other languages, I want someone to help me finish the game (I'll put a special thank in the already done, menu)...
What I want: After the player solve the puzzle, he should find a book (again, a cube with a different texture), in the game universe, the book is a powerful magic item that can open portals, so what I need is a way to, when the player take the book, the portal will allow him to pass to the next level... I know how to load the level (Application.LoadLevel[...]), but I don't know how neither what to do so the portal will only work when the player take the book.
I'm thinking in change the way that the portal works, I was thinking in, when the player takes the book, nothing happens, but when he takes the book and stop in front of the portal, he'll be "teleported" to the other level.
I don't know if I can post my skype here, so I won't, but as I said, I want help and not just a answer, so if someone have the time (something like 1h is enough FOR ME to learn)...
Thank you, and please, don't tell me to learn more Unity, I don't want to be a professional (not yet) I just want to make my game, real, and I want it "now".
Answer by smirlianos · Mar 01, 2013 at 08:33 PM
Ok, look. you should put a boolean to the script of the portal like this
var hasBook : boolean;
var pos2 : GameObject;
function OnTriggerEnter (other : Collider)
{
if(hasBook)
{
player.transform.position = pos2.transform.position
}
}
Then, add this to a script in the key/book
var portal : (name of the script in portal)
function OnTriggerEnter(other : Colider)
{
portal.hasBook = true;
}
when the player walks into the key/book, the boolean in the portal will be set to true, so the player can "teleport" where you want it. (On the first script drag the place where you want the player to "teleport" to the pos2. It should be just an empty gameObject. On the second script drag the book/key on the portal in the inspector
I wrote this supposing you know the basics, like what's a trigger, a GameObject...
Ok, I get it... But the first one... Where do I put it ?
var nextLevel : String;
function OnTriggerEnter() {
//------------//
Application.LoadLevel (0);
//------------//
}
var nextLevel should be an "int" not a "string". "String" is if you want to put a name, or a word. "Int" is if you want to put a number like now, as the levels can be calledwith a number. (0, 1, 2...) If you want to put a "string", you should change the Application.LoadLevel(0) -> application.LoadLevel("nextLevel")
I almost get it... I'm using the portal one like this:
var hasBook : boolean;
var pos2 : GameObject;
var nextLevel : String;
function OnTriggerEnter(other : Collider)
{
if(hasBook)
{
player.transform.position = pos2.transform.position
}
}
//------------//
Application.LoadLevel (0);
//------------//
}
But the console says: "Assets/Standard Assets/Scripts/Portal.js(14,68): UCE0001: ';' expected. Insert a semicolon at the end."
Also if I add a ";" to the end of the line 14, another error shows up.
Your answer
![](https://koobas.hobune.stream/wayback/20220613093641im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Need help. I want to spawn in different position after level reload! 1 Answer
how do you actually stop a game? 3 Answers
Bullet Fire script not working 1 Answer
level loader script wont work 1 Answer