• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KiriLucas · Mar 01, 2013 at 08:12 PM · gamelevelapplication

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".

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hoy_smallfry · Mar 01, 2013 at 08:25 PM 0
Share

Try doing this.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Show 42 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image smirlianos · Mar 01, 2013 at 08:33 PM 0
Share

I wrote this supposing you know the basics, like what's a trigger, a GameObject...

avatar image KiriLucas · Mar 01, 2013 at 09:02 PM 0
Share

Ok, I get it... But the first one... Where do I put it ?

 var nextLevel : String;
 
  
 
 function OnTriggerEnter() {
 
     //------------//
 
     Application.LoadLevel (0);
 
     //------------//
 
 }
avatar image smirlianos · Mar 02, 2013 at 09:53 AM 0
Share

You put it on the script that's on the portal

avatar image smirlianos · Mar 02, 2013 at 10:00 AM 0
Share

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")

avatar image KiriLucas · Mar 02, 2013 at 05:14 PM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Level creator save bug. 0 Answers

Problem stopwatch start the game. 1 Answer

Error... that I don't understand. 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges