Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 names123 · Nov 16, 2011 at 07:24 PM · pickup

Key Pick up

Hi, just have a question if anybody can help me.

In a top-down game i am making, there is a simple puzzle around the idea that the player needs to pick up 3 items (a key) around a level and head to a door, which will open when the player has all 3 keys.

Does anybody know how to do this, where on a button press the key in the environment is destroyed and the game stores how many keys the player has picked up (1,2 or 3) and when the player has all 3 keys, the door will open, otherwise it will remain closed.

Thanks for any help.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by BerggreenDK · Nov 16, 2011 at 07:52 PM

First of all, there are many solutions to this. Its the main idea of most "cave/adventure" ideas that you have to pick up something or enough to pass certain parts of a game.

So, you need some way to generic store your "requested items" if they are different. Like keys in different shapes, colors or materials.

A quick solution if you dont have too many items, could be to have a large array or string where each index is one of the specific items in your game. This array could get expanded as you build the game/level bigger and bigger.

When you pick up something, you just need to assign/attach each item a certain "index" value and this value then matches the array.

Like if you have a function called PickUpItem() which returns an index of 5, then the 5th item in your global itemsInLevel array is the one you have just picked up. Now you can go into the array or string if you like and assign a value to it. Like the count of how many you have or just the items "code/label" if you prefer to have that.

The door that should open, will only check if it can open once you pull the handle or get near it. This function could be called like 1/60 frames thats once pr. second and I believe thats often enough.

The doorscript could be made so it checked for certain indexs to be set or above zero and once this was true, then the door will open.

Does this give you a clue of how to proceed ?

Comment
Add comment · 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
0

Answer by vozochris_1 · Nov 16, 2011 at 09:43 PM

You can do it with bool's. At start make all bool's false. Keys must have a Collider, and if you want set it to Is Trigger.


In Key Script:

make 3 bool's
make Key Type's


bool Keyone = false;
bool Keytwo = false;
bool Keythree = false;
public KeyType keytype = KeyType.one;


make a enum


public enum KeyType(){
one,
owo,
three,
}


if Is Trigger

void OnTriggerEnter(){ }

if is not Trigger

void OnCollisionEnter(){ }

in void enter following


if (keytype == KeyType.one){
Keyone = true;
}

if (keytype == KeyType.two){
Keytwo = true;
}

if (keytype == KeyType.three){
Keythree = true;
}


Make an void Update() to check if Keys are picked up


void Update(){
if(Keyone){
if(Keytwo){
if(Keythree){
// Enter an animation or ... which makes door opened
}}} // Closes all if's
}


Comment
Add comment · Show 1 · 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 munaeem · Sep 09, 2012 at 01:09 PM 0
Share

what kid of person are =, the way you represent code is good but funny. (Y) like it :)

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycasting: Holding an Object 1 Answer

grab things?????with f 2 Answers

Buff System 1 Answer

How do I edit springjoint components in script? 1 Answer

Picking up objects and dropping them 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges