Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 heaversm · Jul 14, 2011 at 05:34 PM · collisioncomponentextensiondetonator

adjusting detonator variables with javascript

Hi - I'm new to unity. Anyone have a good example of how to adjust the detonator unity extension variables with javascript? I just have a basic example set up - sphere falls on plane and explodes.

Sphere has a script that instantiates the explosion on collision:

 var explosion : Transform;
 
 function OnCollisionEnter () {
     Destroy (gameObject);
     var explosionInstance : Transform;
     explosionInstance = Instantiate(explosion,transform.position, transform.rotation);
 }

Explosion is a prefab which contains the detonator-simple prefab. I want to be able to modify the predefined variables of the Detonator script like Duration,Detail,DestroyTime,Size. The simplest example should do fine. Thanks!

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

1 Reply

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

Answer by aldonaletto · Jul 14, 2011 at 05:41 PM

EDITED: I adapted the answer to your script. Now it will find a script called Detonator attached to the explosion clone and let a reference in scriptRef, which you will use to modify the Detonator variables. It should work, but you may have problems if some of these variables are used in the Awake function of Detonator.js - as far as I know, Awake is executed during instantiation, thus before your script can modify anything (I believe Start will be executed only right before the next frame, so the modifications will take effect).

 var explosion : Transform;
 
 function OnCollisionEnter () {
     Destroy (gameObject);
     var explosionInstance : Transform;
     explosionInstance = Instantiate(explosion,transform.position, transform.rotation);
     var scriptRef: Detonator = explosionInstance.GetComponent(Detonator);
     scriptRef.Duration = ...; // modify variables using scriptRef
 }


Comment
Add comment · Show 9 · 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 heaversm · Jul 14, 2011 at 05:44 PM 0
Share

Yes - I can modify the values in the inspector, and I can see the original script for the prefab (Detonator.js) - but I don't want to modify the original script, I just want to modify instances of objects which have the prefab (the script) attached to them. For example, if a sphere falls to the ground that is large, I want the Size value of the explosion to be larger. If the sphere is small, I want to create a small explosion.

avatar image heaversm · Jul 14, 2011 at 05:51 PM 0
Share

This is detonator by the way. Very fun. http://unity3d.com/support/resources/unity-extensions/explosion-framework.html

avatar image aldonaletto · Jul 14, 2011 at 06:01 PM 0
Share

I have already edited my answer to include the modification of variables by script - but right after instantiation. Is it what you're looking for?

avatar image heaversm · Jul 14, 2011 at 06:17 PM 0
Share

Hmmmm, possibly, but I don't think so. I'm not the greatest coder, so it helps me to keep things relevant to my examples. I get what you're saying, but I'm not really instantiating the prefab the way you are above. In my example - Explosion is the prefab from the Detonator framework which contains the Detonator script (and all of its adjustable variables). Sphere is a game object which has been attached the above script. In the inspector, under explosion variable, I have dragged the Explosion prefab. However, it does not work for me to say explosion.Detonator.Size = 1000 - because it is not a member of Unity.Transform. On the other hand, if I instantiate Explosion as a game object, which I think is what you're trying to do above, and change thing, how would I then get my code above to reference this newly modified instance of Explosion?

avatar image aldonaletto · Jul 14, 2011 at 06:40 PM 0
Share

And how do you create the Sphere object? By hand, in the Editor? Or have you created a Sphere prefab, and is instantiating Sphere clones in your script when you need?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

What is the best way to script third person real-time action melee combat in C#? 0 Answers

Can you have different collision box type with one gameobject. 1 Answer

Is this Possible to force gameobjects (coliders etc) to get stretched based on the aspect ratio of the screen? 0 Answers

Analysing player metrics help 0 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