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 FXBaconGames · Sep 06, 2013 at 11:35 PM · javascriptguidestroy

Why doesn't Destroy work?

I am trying to make it so that in the pause menu you can change your character. I want to destroy the original player. However, this isn't working. Any ideas? Boom() destroys the object.

 #pragma strict
 
 var pause = false;
 var RIP;
 
 var prefab : Transform;
 var CS : GameObject;
 var SS : GameObject;
 
 
 function Start () {
     transform.position = CS.transform.position;
     
     Instantiate (SS, transform.position, Quaternion.identity);
 }
 
 function Update () {
 
     if (Input.GetKeyUp ("escape")) {
         pause = true;
         Time.timeScale = 0;
         Debug.Log("babaam");
         
     }
 
 }
 
 function OnGUI() {
     
     if (pause) {
         if (GUI.Button(Rect(Screen.width / 2,Screen.height / 2 - 40,100,30),"Play")) {
             
             Time.timeScale = 1;
             pause = false;
             Debug.Log("Clicked the button with text");
             
         }
         
         if (GUI.Button(Rect(Screen.width / 2,Screen.height / 2,100,30),"Switch")) {
                 transform.position = CS.transform.position;
                 
                 Boom();
                 Instantiate (prefab, transform.position, Quaternion.identity);
             
             Time.timeScale = 1;
             pause = false;
             Debug.Log("Clicked the button with text");
             
         }
         
     }
         
 }
 
 function Boom() {
     RIP = GameObject.Find("player"); 
     Destroy(RIP);
 }
Comment
Add comment · Show 4
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 Garrafote · Sep 07, 2013 at 03:50 AM 0
Share

It seems that everything is fine on your code.

Did you check if your player object is activated? and if there isn't any spelling error with the name of the object?

avatar image clunk47 · Sep 07, 2013 at 04:00 AM 2
Share

You're using pragma strict, try defining RIP's type like you did with your other variables. Also try using a Debug.Log statement in your Boom function, to make sure the function is being fired. Check the case in the spelling of "player" as well.

 var RIP : GameObject;
avatar image FXBaconGames clunk47 · Sep 07, 2013 at 01:31 PM 0
Share

Haha. my fault. It was instantiating the player as player(Clone).

avatar image clunk47 clunk47 · Sep 07, 2013 at 04:36 PM 1
Share

Then you should accept @RyanZimmerman87's answer, since he mentions this. I'll go ahead and to so, glad you got this resolved.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by RyanZimmerman87 · Sep 07, 2013 at 04:03 AM

So is this script attached to an empty object for just the pause menu and some logic? Not attached to the players you are destroying right?

Yeah the solution is not popping out in any obvious way to me. I would probably call the boom() function at the end of your button press logic, I like to keep things ordered sequentially especially when dealing with functions calls which on occasion the position of them has messed things up for me in the past.

Also you might need to do

RIP = GameObject.Find("player(Clone)");

Depending on how you created the original player, but you can see what the name is in Hierarchy.

Not sure if either of those are your problem but that'd be the first think I would check. I also only use C# so maybe I'm missing something else.

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

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

18 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Game Over GUI Question 2 Answers

Unity freezes when changing GUI.Color.a 1 Answer

How can i show the texture in the array? 2 Answers

Detect Text in GUI; Print 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