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 /
This question was closed Dec 04, 2014 at 05:03 AM by Prasanna for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Prasanna · May 23, 2014 at 11:31 AM · c#instantiatedestroy

instantiate object

Hello there, i have a script for bomb creation and destroy with explosion particles. Here is my script definition, i try to create a bomb by pressing space bomb creation it will automatically destroy after 3 seconds, that time i try to instantiate explosion particle. My bomb is created and destroyed perfectly but the particle wasn't. Here is the snippet.

     using UnityEngine;
     using System.Collections;
     
     public class PlayerMove : MonoBehaviour 
     {
         //AI Movement Variables...
         
         public float Speed = 2.0f;
         public Vector3 MoveDirection_Left;
         public Vector3 MoveDirection_Right;
         public GameObject Bomb;
         private GameObject Bomb_Temp;
         public GameObject Explosion;
         private GameObject Explosion_Temp;
         public static bool Bomb_Click, Bomb_Visible;
         public float Bomb_Time = 0;
         public float Explosion_Time = 0;
         
         // Use this for initialization
         void Start () 
         {
             MoveDirection_Left = Vector3.forward;
             MoveDirection_Right = Vector3.right;
             Bomb_Click = false;
             Bomb_Visible = false;
         }
         
         void Bomb_Creation()
         {
             Bomb_Temp = Instantiate (Bomb, transform.position, transform.rotation) as GameObject;
         }
     
         void Bomb_Destroy()
         {
             Destroy(Bomb_Temp, 3.0f);
         }
     
         void Bomb_Explosion()
         {
             Explosion_Temp = Instantiate (Explosion, Bomb_Temp.transform.position, Bomb_Temp.transform.rotation)as GameObject;
         }
     
         void Explosion_Destroy()
         {
             Destroy(Explosion_Temp, 3.0f);
         }
     
         void Update()
         {
             // Character Movement...
             if(Input.GetKey(KeyCode.RightArrow))
             {
                 transform.Translate(-MoveDirection_Right
 * Speed * Time.deltaTime);
             }
             
             if(Input.GetKey(KeyCode.LeftArrow))
             {
                 transform.Translate(MoveDirection_Right
 * Speed * Time.deltaTime);
             }
             
             if(Input.GetKey(KeyCode.UpArrow))
             {
                 transform.Translate(-MoveDirection_Left
 * Speed * Time.deltaTime);
             }
             
             if(Input.GetKey(KeyCode.DownArrow))
             {
                 transform.Translate(MoveDirection_Left
 * Speed * Time.deltaTime);
             }
             
             // Create Bomb...
             if(Input.GetKeyDown ("space"))
             {
                 Bomb_Click = true;
             }
     
             if(Bomb_Click == true)
             {
                 Bomb_Creation();
                 Explosion_Destroy();
                 Debug.Log ("Bomb Created");
                 Bomb_Click = false;
                 Bomb_Visible = true;
             }
             if(Bomb_Visible == true)
             {
                 Bomb_Destroy();
                 Bomb_Explosion();
                 Bomb_Visible = false;
             }
         }
     }

-Prasanna

Comment
Add comment · 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 Benproductions1 · May 23, 2014 at 12:08 PM 1
Share

Please format your code. If you don't know how, watch the tutorial video on the right.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Em3rgency · May 23, 2014 at 12:36 PM

Off the top of my head, I'd say switch Bomb_Explosion() and Bomb_Destroy() places.

You're destroying the bomb, but then using its transform (non existent, because the bomb is destroyed) for the explosion. Call the explosion first, THEN remove the bomb.

Comment
Add comment · Show 1 · 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 Prasanna · May 23, 2014 at 12:42 PM 0
Share

Still same kind of problem.

avatar image
0

Answer by Prasanna · Dec 04, 2014 at 05:02 AM

Here it is, i fix this problem.

 if(Input.touchCount > 0)
         if(Bomb_Button.HitTest(Input.GetTouch(0).position))
         {
 
             if (Instance == true)
             {
                 Bomb_Temp = Instantiate(Bomb, Bomb_Place.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                 Explosion_Position = Bomb_Temp.transform.position;
                 Explosion_Rotation = Bomb_Temp.transform.rotation;
                 Bomb_Click = true;
                 Instance = false;
             }            
         }
         
         if(Bomb_Click == true)
         {
             Bomb_Time += Time.deltaTime;
             if(Bomb_Time >= 3f)
             {
                 Destroy(Bomb_Temp);
                 Bomb_Time = 0;
                 Bomb_Click = false;
                 Bomb_Visible = true;
                 Expose_Instance = true;
             }
         }
         
         if(Bomb_Visible == true)
         {
             if(Expose_Instance == true)
             {
                 audio.PlayOneShot (Explosion_Sound);
                 Explosion_Temp = Instantiate (Explosion, Explosion_Position, Explosion_Rotation)as GameObject;
                 Expose_Instance = false;
             }
             Explosion_Time += Time.deltaTime;
             if(Explosion_Time >= 2f)
             {
                 Destroy(Explosion_Temp);
                 Explosion_Time = 0;
                 Bomb_Visible = false;
                 Instance = true;
             }
         }
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

Follow this Question

Answers Answers and Comments

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

Related Questions

What's a better way to code in chunks 1 Answer

How to destroy an instantiated prefab object and keep instantiating it 1 Answer

C# override a destroyed GameObject in a List 1 Answer

How to determine and delete the oldest instantiated object? 2 Answers

Why is destroying a GameObject also destroying all GameObjects created by said object via Instantiate? 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