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 /
This question was closed Mar 24, 2014 at 01:08 PM by AlucardJay for the following reason:

The question is answered, right answer was accepted; Duplicate Question; Asking for Script

avatar image
0
Question by Pigifying · Mar 22, 2014 at 04:43 PM · pickupdissapear

Picking up an object with a key.

Basically im making a 3D game and I need a script so when I enter a Collider, I can then press E to make the object dissapear. I also want to have a AudioClip play once I press E too. I just really need a script not a reference because I always fail at those. Please anyone who can help. Cheers

Comment
Add comment · Show 5
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 getyour411 · Mar 22, 2014 at 04:43 PM 0
Share

When is your homework due?

avatar image supernat · Mar 22, 2014 at 04:46 PM 0
Share

Unity Answers is not here to ask for others to do your work. Check out elance.com for that.

avatar image Pigifying · Mar 23, 2014 at 06:17 PM 0
Share

I just can't get it right. Ive tried and tried but i just can't get it to work. Ive tried everything even raycasting but it all fails.

avatar image getyour411 · Mar 23, 2014 at 06:45 PM 0
Share

I'm sure the OP will say 'uhuh man, this is for real', but my original comment was based on the fact that this exact same question is asked all the time (re: press E in a collider to interact w/ object and playsound). So often, with the exact same details, that it just feels like a homework assignment from somewhere out there in Game Program$$anonymous$$g 101 land.

avatar image Pigifying · Mar 24, 2014 at 12:00 PM 0
Share

OHHHH ok because im like dude, im in middle school. Wow i didn't even know that.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by SkaredCreations · Mar 23, 2014 at 06:37 PM

I'll write the code now, it's really easy so I don't know why you're having so much issues, but if you want to use Unity and you haven't experience at all in programming then you should really find a programmer as partner for your game or learn some programming basics else you will be here on Answers most of your time :)

Here is:

     public AudioClip myAudioClip;
     bool isInside = false;
 
     void OnTriggerEnter (Collider other) {
         isInside = true;
     }
     void OnTriggerExit (Collider other) {
         isInside = false;
     }
 
     void Update () {
         if (Input.GetKeyUp(KeyCode.E) && isInside) {
             audio.PlayOneShot(myAudioClip);
             Destroy(gameObject);
         }
     }

This code presumes that your collider is set as Trigger and you have an AudioSource component attached to the gameobject. The script should be attached to your target collider, not your player of course.

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 Pigifying · Mar 24, 2014 at 12:03 PM 0
Share

Thank you the script worked beautifully I appreciate the time and effort you took to make this script and have a nice day! - Pig

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Change Pickup key 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 Answers

Making A Universal Pickup Script 1 Answer


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