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 Szygani · Apr 12, 2012 at 11:14 AM · collisioncolliderontriggerenterdestroy object

Help with school project, collision, destroying objects

Hello guys, I was wondering if you guys could help me out. It's the last thing that needs to happen and then I'm sure to win a prize with this thing at school!

Okay, so here is the problem. I have a first person perspective game, where people need to run through a level as fast as they can. They need to visit certain key points ("cyrstals") before the level is finished. I was going to do this by having them collide with these crystals.

I have 7 crystals through the level.

How do I make it so that it registers the collision between the object, destroys the light effect of it so that you can see you've seen it already, and register how much you've collided as well?

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
1

Answer by Kryptos · Apr 12, 2012 at 11:43 AM

Add a script to your crystal that deals with physics trigger detection. You will need to have a collider on each crystal (a BoxCollider or a SphereCollider should do the job).

Example of script:

 void OnTriggerEnter( Collider other )
 {
     // test to make sure the player hit the trigger
     // for example:
     if(other.gameObject.name == "Player")
     {
         // call a method on the player to increment a counter
         other.gameObject.GetComponent<PlayerScript>().PlusOne();

         // destroy the crystal
         Destroy( this.gameObject );

         // or disable light
         DisableLight();
         // and remove collider
         Destroy(GetComponent<Collider>());
     }
 }


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 Szygani · Apr 12, 2012 at 02:20 PM 0
Share

You're a beautiful person, thank you. :)

avatar image
0

Answer by fafase · Apr 12, 2012 at 12:58 PM

Almost the same in Js. Add this one to your crystal ball prefab, I would guess the lighting system is childed:

Crystal.js

 static var count: int = 7;
 var pling :AudioClip;

 function OnTriggerEnter(other:Collider){
    if(other.gameObject.tag =="Player"){
         count -=1;
         AudioSource.PlayAtPoint(pling,transform.position);
         Destroy(gameObject); 
 }

on your player or level ground or any object that will remain

 function Update(){
    if(Crystal.count == 0)
    {
       Application.LoadLevel("WinningScreen");
    }
 }
Comment
Add comment · Show 4 · 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 Kryptos · Apr 12, 2012 at 01:02 PM 0
Share

I guess you mean count -= 1 if you want to load a level when the count reaches 0.

avatar image fafase · Apr 12, 2012 at 01:33 PM 0
Share

Indeed I meant. I edit right on.

avatar image Szygani · Apr 12, 2012 at 02:20 PM 0
Share

Thank you very much, that did the trick. I'm going to use the C# version posted above, as the rest is in C# as well. Thanks though! :D

avatar image fafase · Apr 13, 2012 at 07:37 AM 0
Share

I am not pushing you to use $$anonymous$$e, but just in case you would not know, you actually can mix c# and js scripts. Unity detects which language is used and compile them to binary. So just for you to know that if you found a script in the other language you wouldn't need to translate 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

Accessing a collider's collisions without OnTriggerEnter or OnTriggerStay 1 Answer

Collision Handling for a Fighting Game 1 Answer

Collision Checking 1 Answer

OnTriggerEnter does not work 1 Answer

Trying to detect multiple points on a single collider 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