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 KirinXHell · Dec 13, 2014 at 11:31 AM · instantiateprefabclonelifehealth

Destroy 1 prefab object and changing the color/image

I want to destroy a created prefab (not all the prefab) and change the color or creating a new prefab on it. I figure out how to create a new image by using Instantiate on the destroyed position and/or changing the color by using renderer material color. But I want to know how to destroy 1 prefab/clone object that use Instantiate first before doing the rest. Anyone can give me hint or idea on how to do it? Tried using Destroy(this.gameObject), Destroy(gameObject), Destroy(GameObject.FindWithTag), etc but they destroy all of my life.

alt text

 using UnityEngine;
 using System.Collections;
 
 public class Life : MonoBehaviour {
     
     private GameObject gc;
     private GameControl gcs;
     public GameObject lifePrefab;
 
     // Use this for initialization
     void Start () {
         gc = GameObject.Find ("GameControl");
         gcs = gc.GetComponent<GameControl>();
     }
     
     // Update is called once per frame
     void Update () {
             // Get the current life from GameControl
         if(gcs.getLife() == 2){
 
             //  Some code here to destroy 1 prefab life
 
             // Create new different prefab at the same position
             Vector3 newLifePos = new Vector3(-1.4f,0.6f,0);
             Instantiate(lifePrefab, newLifePos, Quaternion.identity);
         }
 
     }
 }
 
untitled.png (332.5 kB)
Comment
Add comment · Show 2
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 Qasem2014 · Dec 13, 2014 at 11:51 AM 0
Share

use destroy(this,1) ! this script should be on the prefab ! then it destroyed after its create after 1 second ! not matter it have the same name by the other cloned object

avatar image KirinXHell · Dec 14, 2014 at 12:43 PM 0
Share

Thanks for the comment, but I just wanted to destroy one of the prefab(life) based on how many life I get deducted.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ericool · Dec 14, 2014 at 01:49 AM

If I may if your prefab is just a texture you should keep the reference and just change the maintexture. But in your case I suggest you to do Destroy(gameObject) then in your gameObject script put the method OnDestroy(){Instantiate(another)}; Or if you have destructor ~MyClass that's fine too , but it cannot be inherited from MonoBehaviour although .

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 KirinXHell · Dec 14, 2014 at 12:45 PM 0
Share

Thanks for the reply, I tried your method of destroying the entire gameObject and using OnDestroy() to instantiate new one (which is 2 life), but it will have some weird behaviour like infinite loop of the life(clone) because of gcs.getLife() == 2. Tried using a boolean and integer to check for it but to no avail.

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

How do you change the int of an object in the scene with an instantiated button? 1 Answer

(Clone) from Instantiated Prefabs over Network 1 Answer

How to instantiate from prefab, not from instance? 3 Answers

Assign an instantiated GameObject? 1 Answer

Prefab shooting damage/health? 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