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 adamchakov · Mar 01, 2014 at 06:12 PM · destroywaitforsecondsboxinstatiate

instatiate gameobject after 1 second

--hey guys , after 1 SECOND from when this box is destroyed , i want to instantiate a gameobject.

--note : please i want to instantiate the gameobject after 1 SECOND from when the box was destroyed. thanks !

 var fruit : GameObject;
 
 function OnTriggerEnter(other: Collider){
   
   if (other.CompareTag("Spin")){
   
   
 
   
     Destroy(gameObject);
   }
 }
 
 function OnDestroy () {
 
 
 var gameobject : GameObject = Instantiate(fruit,transform.position, transform.rotation);
 
 }
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
0
Wiki

Answer by mclankyman · Mar 01, 2014 at 06:19 PM

If you have a game controller game object which handles the instantiation of the Fruit Object and give that game controller a script it should work. It did with this code. I gave the gamecontroller a script called OtherClass.

This game object is destroyed when you click it and will call a method from the other class (which will still exist after you destroy this one).

 public class destroy : MonoBehaviour {
 public OtherClass other;
 
     void Awake()
     {
         other = GameObject.FindGameObjectWithTag ("GameController").GetComponent<OtherClass>();
     }
     
     void OnMouseDown()
     {
         Destroy(gameObject);
     }
     
     void OnDestroy()
     {
         other.delayedInstantiate();
     }
 }


The other class handles the delay.

 public class OtherClass : MonoBehaviour{
 
 public GameObject fruit;
 
     public void delayedInstantiate()
     {
         Invoke("InstantiateFruit", 1f);
     }
     
     private void InstantiateFruit()
     {
         Instantiate(fruit);
     }
 }
Comment
Add comment · Show 6 · 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 adamchakov · Mar 01, 2014 at 06:54 PM 0
Share

@mclankyman hey dude thanks for the reply , i didn't know how to add it in my script , please would help me with this ?thanks

avatar image adamchakov · Mar 02, 2014 at 12:23 AM 0
Share

thanks for the script @mclankyman , but when i destroy the box , the fruit didn't spawn at all :/

avatar image whydoidoit · Mar 02, 2014 at 03:38 AM 1
Share

It won't because the thing being invoked has been destroyed. You cannot Invoke on the same object - try invoking on another one or delaying the destruction until after the delay (just turn off the renderer and collider).

avatar image mclankyman · Mar 02, 2014 at 10:51 AM 0
Share

can you put the CreateFruit function in another script? One that is still alive?

avatar image adamchakov · Mar 02, 2014 at 01:42 PM 0
Share

yeah i can but , how can i spawn the fruit after one second from when the box is destroyed ( from another new script) , help ! thanks !

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

instatiate gameobject after 1 second 1 Answer

Particle system show up when gameobject gets destroyed 1 Answer

Explosion triggers another explosion 2 Answers

How can I select, single out and zoom into my object? 2 Answers

make collider enabled when another object is destroyed 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