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 Carl 2 · May 05, 2011 at 09:25 PM · spawnoncollisionenterifexplosion

Spawning an explosion using an IF statment

I'm very sorry if this has been asked before, but I can't seem to figure this out.

Basically I want an explosion to spawn at the location of where an object is destroyed. I know this is a rather simple thing to do, but the script I've got for collisions is applied to the player.

I was wondering how I would write an IF statment in the script that is applied to the player to make an explosion spawn at the location of the destroyed objects.

Thanks for your time :)

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 Owen-Reynolds · May 06, 2011 at 04:29 AM 0
Share

So, if a rock hits the player, you want an explosion right at that point? Or you want the rocks to explode where they hit, no matter what they are hitting? In general, put the explosion spawn (and die) on the object being destroyed, not on the player.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sebas · May 05, 2011 at 10:37 PM

From the documents: "In contrast to OnTriggerEnter, OnCollisionEnter is passed the Collision class and not a Collider."

Taking this further, you can access collision information such as the gameObject or collider that you hit. Once you have the gameObject, you can get the position/transform, spawn an explosion, do other stuff...

function OnTriggerEnter(collisionInfo : Collision)
{   
    if (collisionInfo.gameObject.tag == "ExplodingGameObject"){
       //explode
       //use collisionInfo.transform.position to grab the location you need)
    }
}
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 Carl 2 · May 06, 2011 at 01:26 PM 0
Share

Thanks for the reply, I'll try it out :)

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

No one has followed this question yet.

Related Questions

Spawning issues 0 Answers

Why the "Detonator Explosion Framework" from AssetStore don't render in compiled game? 0 Answers

Spawning explosions and detecting objects in range 1 Answer

Explosion prefab spawns only the first time in my published app, but spawns on every collision inside Unity Game mode. 1 Answer

Teleporting script won't work 2 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