• 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
Question by Sun_Glasses_Guy · Jul 14, 2011 at 02:00 AM · javascriptweaponexplosionremotebomb

Help With Remote Explosive

/I USE JAVASCRIPT\

Hey I'm doing a little practice project. The basic concept is some C4, in my scripts I call it a grenadeProp and the button that detonates it, the grenadeRemoteProp

(prop because they're the objects the player holds, the thrown grenade is just called grenade or grenadePrefab)

So I have almost everyt$$anonymous$$ng working for the remotely detonated grenade, let's just call it C4 for easy reference. I have the animations, and I can get the grenadePrefab to spawn. But it doesn't work quite right. I use a master script for the weapons FYI (FirePrimary is the Fire1 button) and (FireSecondery is the Fire2 button) that broadcast those button's inputs to the other scripts.

I'm trying to make the grenadePrefab explode when I broadcast the message FirePrimary using a detonate var from the grenadeRemoteProp's script and it should destroy the grenadPrefab, and instantiate an explosion.

So I've fiddled around with my scripts and I can either get get the grenade to destroy itself, but not spawn the explosion. Or get the grenadePrefab to spawn an explosion on itself and then instantiate itself every frame infinitely.

So I've reached a point where I can't find the answer anywhere (maybe I'm looking for the wrong keywords) and I need some help!

Here's the script for the Grenade Prefab:

 var grenadeController:Transform;
 var explosionPrefab:Transform;
 
 function Update () {
 var detonate = grenadeController.GetComponent(wGrenadeRemoteProp).detonate;        
 
     if(detonate >= 1)
         Destroy(gameObject, 0.2f);
         
         explosion = Instantiate(explosionPrefab, gameObject.transform.position, Quaternion.identity);
     
     
     
 }

And here's the GrenadeRemoteProp's Script:

 var Thrown = 0;
 public var detonate = 0;
 
 function FirePrimary () {
     detonate += 1;
 }
 
 function FireSecondary () {
     if(Thrown >= 1)
         return;
     if(Thrown < 0)
     Thrown += 1;
     animation.Play("GrenadeThrow02");
     
 }
Comment

People who like this

0 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 FLASHDENMARK · Jul 14, 2011 at 06:21 PM 0
Share

Whether you use Javascript or C# is irrelevant a helping hand is a helping hand no matter if it is left or right handed.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Chris D · Jul 14, 2011 at 06:08 PM

T$$anonymous$$s is your problem:

 if(detonate >= 1)
     Destroy(gameObject, 0.2f);

     explosion = Instantiate(explosionPrefab, gameObject.transform.position, Quaternion.identity);

You're destroying the gameObject (and the instance of t$$anonymous$$s script) before it has a chance to instantiate the explosion.

Switch the order.

Comment
FLASHDENMARK

People who like this

1 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Variable Access Problem (Javascript) 3 Answers

timed bomb, explosion detection 2 Answers

OverlapSphere not causing damage? - Solved 2 Answers

Object only explodes when it collides with certain object, not all rigidbodies. 2 Answers

Mario Kart Style random weapon 3 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