• 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 everything 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

  • Sort: 
avatar image

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

This 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 this 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

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

Exporting FBX via 3ds Max doesn't show 'Bomb' modifier 2 Answers

Can't get 2d bomb to explode on timer 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