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 xbennettx821 · Jul 09, 2011 at 02:03 AM · destroyspawntimer

Spawning Particle Effects From Code Does Nothing

I made a Squirtle and I want to make it do a Bubblebeam attack that starts and continues for a few seconds, then gets destroyed, then has a wait before it can be done again. I want the Bubblebeam to spawn from his tongue, which is a separate part of the mesh. And the Bubblebeam is a particle effect. My code goes like this:

Heading

 static function UseBubblebeam (Tongue : GameObject, 
                                BubblebeamPrefab : GameObject, 
                                Bubblebeam : Transform) {
 if (Input.GetKey("[1]")){
     var BubblebeamAttack : GameObject = Instantiate (BubblebeamPrefab, Tongue.transform.position, Tongue.transform.rotation);
     yield WaitForSeconds(3.0);
     Destroy (Bubblebeam);
     yield WaitForSeconds(5.0);
     }
 }

There are no error messages but when I press the button nothing happens... Does this have to do with the input? (and I have tried both the numPad and the row at the top of the keyboard)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Jul 09, 2011 at 02:57 AM

You're checking for Input.GetKey inside the function UseBubblebeam. You should check for input in Update, since it's called each frame.

EDITED AGAIN: Answer edited to destroy the instantiated object after 3 seconds, and to include a reload time of 5 seconds:

 var Tongue : GameObject;
 var BubblebeamPrefab : GameObject;
 var nextShot : float = 0;
 
 function UseBubblebeam () {
 
     var BubblebeamAttack : GameObject = Instantiate (BubblebeamPrefab, Tongue.transform.position, Tongue.transform.rotation);
     Destroy (BubblebeamAttack, 3); // destroy automatically after 3 seconds
 }
 
 function Update(){
 
     if (Time.time>nextShot && Input.GetKeyDown("[1]")){
     
         UseBubblebeam();
         nextShot = Time.time + 5; // next shot in 5 seconds   
     }
 }

You must drag the objects you want to the variables Tongue and BubblebeamPrefab. When you press 1 in the keypad, BubblebeamPrefab will be instantiated at Tongue position, and will be destroyed automatically after 3 seconds. The reload time was set to 5 seconds.

Comment
Add comment · Show 8 · 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 xbennettx821 · Jul 10, 2011 at 06:29 PM 0
Share

@aldonaletto Your note is correct. However, that code brings the error message "Destroying assets is not permitted to avoid data loss." I don't want the actual prefab in the project view destroyed, but in the code I want an object to be created and last for three seconds (the empty mesh for the particle effect), and then for the mesh (not the prefab from the project view) to get destroyed and have a reload time of five seconds. How might I do that? (BTW I'm a total noob at javascript in case you haven't noticed..)

avatar image aldonaletto · Jul 10, 2011 at 07:53 PM 0
Share

I edited the answer to create the BubblebeamAttack and destroy it after 3 seconds. But what about the mesh you've mentioned? Is it the Tongue? You must do the same thing you've did with BubblebeamPrefab: instantiate it at certain position, then destroy it after some time. You can also use Destroy(object, delay), and the object will automatically be deleted after the specified delay.

avatar image xbennettx821 · Jul 10, 2011 at 10:17 PM 0
Share

Well the tongue is where I want it to spawn. I don't want the tongue to be destroyed which hasn't happened with the recent revisions. But now when I try to press the 1 key again, nothing happens even if I remove the second yield. Could that be because the variable gets destroyed in the script?

avatar image aldonaletto · Jul 10, 2011 at 10:34 PM 0
Share

In the script above, only the instance created is destroyed. The prefab will be kept alive and safe. It should work anytime you pressed the keypad key 1.

avatar image aldonaletto · Jul 10, 2011 at 10:42 PM 0
Share

I edited the answer again to include the reload time. It's 5 seconds from the last shot. If you want it to be 5 seconds after the end of the last shot, raise the time to 8 in the last line.

Show more comments
avatar image
0

Answer by xbennettx821 · Jul 12, 2011 at 05:57 PM

The BubblebeamPrefab is an empty mesh with a particle system attatched. I'm starting to think it would've been smarter to just make the particle system on the tongue and make the emitter a boo. I'll try experimenting with that but thanks a bundle for the help :D

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Respawn destroyed object 1 Answer

Instantiated object is destroyed in scene, but still logs as existing in console. 1 Answer

Timer with 5-6 rounds that spawns enemies then end game 0 Answers

Timer Spawn Freezing Unity C# 1 Answer

Destroy GUI-Window after 3 Seconds.... 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