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 Dann858 · Jan 22, 2013 at 06:30 PM · c#tutorial

DestroyObject() and load a new object.

I'm trying to remove the object (in this case a cube that attacks me by using)

 DestroyObject(enemy)


and this works. But now I try to create a new GameObject that has not been shown in the scene. It has to present the body of the 'dead' cube.

I'm just trying things out on cubes etc. until I create some nice models and animate everything.

If possible I'd also like to know how to disable certain scripts. Like I want to disable the EnemyAttack and EnemyAI scripts.

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 Wiki

Answer by sdgd · Jan 22, 2013 at 07:09 PM

answer in C#

 public GameObject PrefabEnemy ;

 example (){
 PrefabEnemy = Instantiate(PrefabEnemy) as GameObject ; // we create GO and name same object as PrefabEnemy (if it's name is Enemy it'll be enemy(Clone))
 }


but you should know that Dead enemy can be same body in animation with gravity on and all physics and all scripts off so he doesn't move but the mesh works

how to disable Scripts:

 this.enabled = false ; // disables your script
Comment
Add comment · Show 2 · 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 Dann858 · Jan 22, 2013 at 08:43 PM 0
Share

It does work, and it creates a the 'dead' cube. But it creates LOADS and LOADS for Cube(Clone)(Clone)(etc.)(etc.)(etc.). How do I get rid of that?

avatar image sdgd · Jan 30, 2013 at 01:59 AM 0
Share

ah yeah he is duplicating him self

to get rid of that you must copy the first one like:

 public GameObject PrefabEnemy ;
 public GameObject Enemy ;
 
 example (){
 Enemy = Instantiate(PrefabEnemy) as GameObject ; // we create GO and name same object as Enemy (if it's name is Enemy it'll be enemy(Clone))
 }

so what happened the name was enemy(Clone) so it spawned enemy(Clone)(Clone)

after that was name enemy(Clone)(Clone) so it spawned enemy(Clone)(Clone)(Clone)

well you get the idea

so now we've named Enemy with enemy so it should always give you enemy(Clone)

well... IF you are trying to instantiate object and than read it you need different approach as you'll delete the Object that you need to read from and it'll give you Null

look at:

how to instantiate object with content prefab and not him self

hope it helps understanding

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Help writing a Login for Unity using PHP and SQL 1 Answer

Any good tutorials for C#? 1 Answer

is expected error 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