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 Patricolo · Jan 25, 2014 at 08:52 AM · variabledestroy object

the object is not destroyed to the preset value

Hello to all! I ask in advance sorry for my bad English (I use google translate: () I would like to know why the value of the variable object is not destroyed

 using UnityEngine;
 using System.Collections;
 
 
 
 public class  des   : MonoBehaviour
 {
     public int vita = 100;
     public GameObject oggetto;
     private void OnCollisionEnter(Collision c )
     {
         vita +=1;// add one value
         if(vita == 5) // if value == 5
         {
         GameObject.Destroy (this.gameObject);// not work
         Instantiate(oggetto, transform.position, Quaternion.identity); // not work 
         }
 
 
 
     }
 }
 
 
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
0

Answer by getyour411 · Jan 25, 2014 at 08:55 AM

Change

 GameObject.Destroy(...)

to

 Destroy(...)

and you might need to change

 this.gameObject

to

 c.gameObject

but not sure - are you trying to destroy the gameobject the script is attached to, or the gameobject that hit the CollisionEnter?

If you wanted to destroy this.gameObject, move the instantiate line above that so it instantiates first before destroying (itself)

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 Patricolo · Jan 25, 2014 at 11:21 AM 0
Share

ok solved!

the solution?

and that I did not realize that the values ​​increased

every time the projectile was in collision and did not have to make that set the preferred values

Sorry my Bad english

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

How do you get a function to 'check' a previous function has occurred in order to trigger a second function? 1 Answer

Hi Im just trying to get my projectile to destroy a game object and Im having a hard time figuring it out. Any help is appreciated.c# :) 1 Answer

Make a game object in a scene into a prefab with script 1 Answer

Destroying one of enemies stored in an array, 1 Answer

how to make the character look at the object and when clicked on mouse0 the object is removed with sound? 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