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 Deathspank · Oct 03, 2013 at 09:54 AM · collisiongameobjectexplosiondeletepower-up

[SOLVE] 2D Space shooter - explosion power-up scripting, please help!

I'm making a 2D space shooter and want to have a power-up system.

Edit : I know my script is wrong, I want the player to trigger the power-up, and the power-up only affects the gameObjects tag with Enemy, as I want to delete everything that is collides/inside the explosion prefab when it triggers, I also want this to occur for at least 5 seconds. I hope this edit clear things up

I want that if my player collides with the gameObject, it will create an explosion that will destroy all the enemies that enters it and all that was already inside it.

I have this right now

 using UnityEngine;
 using System.Collections;
 
 public class FusionPowerUp : MonoBehaviour 
 {
  public GameObject fusPrefab;
 
     void OnTriggerEnter(Collider otherObject)
     {
         if(otherObject.tag == "Player")
         {
          var expPrefab = Instantiate(fusPrefab, this.transform.position, Quaternion.identity);
 
 
 //Destroy(gameObject.tag = "Enemy"); // not working
 Destroy(expPrefab, 2f);
 Destroy(this.gameObject);
         }
 }

}

So right now when my player hits the object, it shows the explosion prefab, but thats all I've got. Also how do I allow my player to go pass this object, as right now the expPrefab collider doesn't allow my player to pass through it.

Also about scoring, how do I check when an enemy dies from the explosion and add it to my score? Right now I can add score when I shoot something with my bullet collider, but with this power-up it could destroy more than one enemy at a time.

Please help!

Thank you very much

Comment
Add comment · Show 3
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 Deathspank · Oct 03, 2013 at 10:39 AM 1
Share

Please guys help me with this simple question

avatar image Tanshaydar · Oct 03, 2013 at 11:02 AM 0
Share

One question at a time dude :) Well, firstly, make sure you checked the box isTrigger to make the collider a trigger area.

Before destroying the trigger area, you should destroy all enemies. In your code, you say if otherObject.tag is Player, but if it is player how can it be also Enemy? You need to change the structure. If you explain one by one, people here will help you better and faster.

avatar image Deathspank · Oct 03, 2013 at 11:17 AM 0
Share

Oh I really don't know how to do that, I want the player to trigger the power-up object but I want the effects to only affect the enemy.

So how would I script that? Please help

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tanshaydar · Oct 03, 2013 at 11:26 AM

This is just brainstorming. Have a Sphere collider for power up object. Check it isTrigger on inspector screen and when the player enters, have a boolean playerEntered that becomes true.

Then you can destroy power up object in, let's say, 2 seconds. When that boolean is true you can do something like this:

 void OnTriggerEnter(Collider otherObject)
     {
         if(otherObject.tag == "Player")
         {
               playerEntered = true;
               var expPrefab = Instantiate(fusPrefab, this.transform.position, Quaternion.identity);
               Destroy(expPrefab, 2f);
               Destroy(this.gameObject, 1.2f);
         }
 }
 
 void OnTriggerStay(Collider otherObject)
     {
         if(otherObject.tag == "Enemy" && playerEntered)
         {
               Destroy( otherObject);
         }
     }
Comment
Add comment · Show 14 · 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 Deathspank · Oct 03, 2013 at 12:18 PM 0
Share

I will try this now, give me 5 $$anonymous$$utes, sorry I missed this answer.

avatar image Deathspank · Oct 03, 2013 at 12:26 PM 0
Share

Ok It doesn't delete the enemies, both enemies and the player just passes through the expPrefab.

Both my enemies and expPrefab have a collider and isTriggered.

avatar image Tanshaydar · Oct 03, 2013 at 12:32 PM 0
Share

This script was not a "finalized working script", it is just an idea about how to achieve your goal. Also, you should place this script on prefab object, not on the player or the enemy. $$anonymous$$ake sure your player is tagged as Player and enemies are tagged as Enemy.

avatar image Deathspank · Oct 03, 2013 at 12:49 PM 0
Share

Sorry the script is working like what I had before, it just doesn't delete the enemies. $$anonymous$$y player can successfully collide with the power-up box object, and it explodes. The problem is that the explosion doesn't delete any enemies.

I have all the tags correct, both have sphere collider and isTriggered on.

avatar image Tanshaydar · Oct 03, 2013 at 12:52 PM 0
Share

Which sphere collider you are using to detect enemies? Explosion prefab's? Player's? Enemies'? Power up object's?

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Exploding two gameobjects from the center of an collision 1 Answer

Detect cloned object detection once 0 Answers

Collider2D.GetContacts() always returns only 1 contact 1 Answer

OnCollisionEnter Collision not detected? 1 Answer

Get the script instance associated with a 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