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 MC HALO · Nov 02, 2010 at 05:52 AM · collisiongameobjectupdaterespawn

Stop Object from deleting HELP ME!!!!!!!!!!!!

Hey guys i just noticed something i made a script earlier on which enables and disables my scripts when the right key is pressed it enables it or disables it. I will give an example When i press the N key my current player will get deleted from the prefab that it came from and the new object will show up, and at the end it will stop the move script for the first player. Now the problem is when i press the M key it should bring back the main Player that i was using but it brings up nothing it deletes the second player and then does not transform the main player back this is because it has deleted my Player from the prefab i was wondering if i could turn its Check Box of instead of deleting the player here is my script:

//drag your spawn point to here in the inspector - probably make it an empty gameobject so you can move it about on the diving board

var spawnPlayer1 : Transform;

var MainPlayerPlayer2: GameObject;

var NewPlayerPrefab2 : Transform;

function Update()

{

if(Input.GetKey(KeyCode.M)){

Destroy(MainPlayerPlayer2); // this is the main line, this deletes the gameobject can i disable it instead?

 Instantiate(NewPlayerPrefab2,spawnPlayer1.position,spawnPlayer1.rotation);

 GetComponent(NewMoveScript).enabled = true;           


} }

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
3
Best Answer

Answer by TheDemiurge · Nov 02, 2010 at 06:17 AM

What Destroy does is to remove an object from the scene, or to remove a component from an object. I would use SetActiveResursively. This is the same as clicking that little checkbox at the top-left corner of the Inspector. The main difference with this and GameObject.active is that this one also turns any child objects on and off at the same time. This way when you turn the first player back on, whatever information they had - position, direction, speed (and higher level stuff like current weapon, ammo, gold, health, etc) are all as they were.

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 MC HALO · Nov 02, 2010 at 06:40 AM 0
Share

Thank you very much :) But now i am getting a different problem it now makes duplicates of the player and activating the script no longer works the player shows up perfectly :)

avatar image TheDemiurge · Nov 07, 2010 at 09:45 AM 0
Share

Did you delete the line with the Instantiate? That's likely what's duplicating the player. As for activating the script, components (such as $$anonymous$$onoBehaviour) that are enabled, will automatically disable when you disable the GameObject they're attached to, and automatically enable when you reactivate that GameObject. So you shouldn't technically have to enable it yourself.

If you need to do certain things with each player just before, or just after it gets turned on or off, you can use the OnEnable and OnDisable functions.

Sorry about late reply, thing doesn't email on 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

No one has followed this question yet.

Related Questions

A node in a childnode? 1 Answer

How could it be done "Cooldown" for a shield ? 2 Answers

Collision for a 2d Top Down RPG using 2d Toolkit 1 Answer

Best way to - Animation Sync - Multiple gameObjects. 0 Answers

How to create 3D game object in specified pixel size? 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