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 gravelpootis · Feb 24, 2021 at 04:08 PM · class object

class object is not destroying

 public class C_Shell : MonoBehaviour
 {
     public GameObject shellObject;
     public bool countdown;
     public float deleteTime;
     public Vector3 velocity;
     public Vector3 position;
 
     public C_Shell(GameObject _shellObject, float _deleteTime, bool _countdown, Vector3 _position, Vector3 _velocity)
     {
         this.shellObject = _shellObject;
         this.countdown = _countdown;
         this.deleteTime = _deleteTime;
         this.position = _position;
         this.velocity = _velocity;
     }
 
     public void SelfDestruct()
     {
         Destroy(this, this.deleteTime);
     }
 
     public void UpdateObject()
     {
         this.shellObject.transform.position = this.position;
     }
 }
 
 public class Shell_Manager : MonoBehaviour
 {
     public static Shell_Manager instance;
 
     public const int maxShells = 128;
 
     public List<C_Shell> shells;
 
     public float deleteTime = 3.0f;
 
     private void Awake()
     {
         if (instance == null)
             instance = this;
     }
 
     private void Start()
     {
     }
 
     private void Update()
     {
     }
 
     private void FixedUpdate()
     {
         UpdateShells();
     }
 
     private void UpdateShells()
     {
         int index = 0;
         foreach (C_Shell shell in shells)
         {
             shell.SelfDestruct();
 
             shell.countdown = true;
             shell.position += shell.velocity * Time.fixedDeltaTime;
             shell.position += Physics.gravity * Time.fixedDeltaTime;
 
             index++;
         }
 
 
     }
 
     public void FireShell(ShellFire _shell)
     {
         Vector3 initialPosition = _shell.initialPosition;
         Quaternion initialAngle = _shell.initialAngle;
 
         switch (_shell.eShellType)
         {
             case EShellType.AP:
                 {
                     Fire_AP(initialPosition, initialAngle);
                     break;
                 }
             case EShellType.HE:
                 {
                     Fire_HE(initialPosition, initialAngle);
                     break;
                 }
         }
     }
 
     void Fire_AP(Vector3 _initialPosition, Quaternion _initialAngle)
     {
         Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Resources/Prefabs/Shell.prefab", typeof(GameObject));
 
         shells.Add(new C_Shell(Instantiate(prefab, _initialPosition, _initialAngle) as GameObject, deleteTime, false, _initialPosition, Vector3.forward * C_AP.constants.force));
     }
 
     void Fire_HE(Vector3 _initialPosition, Quaternion _initialAngle)
     {
         Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Resources/Prefabs/Shell.prefab", typeof(GameObject));
 
         shells.Add(new C_Shell(Instantiate(prefab, _initialPosition, _initialAngle) as GameObject, deleteTime, false, _initialPosition, Vector3.forward * C_HE.constants.force));
     }
 }

I dont know why is C_Shell object not being destroyed

Comment
Add comment · Show 3
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 AllTheGoodNamesWereTaken · Feb 24, 2021 at 04:50 PM 0
Share

Destroy(this); is destroying the script that is attached to the object. You may want to use Destroy(this.gameObject, this.deleteTime);

avatar image gravelpootis AllTheGoodNamesWereTaken · Feb 24, 2021 at 05:44 PM 0
Share

I want to destroy class object

avatar image AllTheGoodNamesWereTaken gravelpootis · Feb 24, 2021 at 10:29 PM 0
Share

Just for clarification, you're creating a C_Shell object that you are firing. It initiates correctly but the SelfDestruct() is not activating?

1 Reply

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

Answer by HoweToGaming · Feb 24, 2021 at 11:17 PM

are you trying to do something like this

 public void SelfDestruct(C_Shell shell)
     {
         Destroy(shell);
     }
 
 // and call it with 
 C_Shell.SelfDestruct(shell);
 

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

113 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I check if a derived class is a certain class? 1 Answer

Object is null when it shouldn't be. 1 Answer

making Turrets 0 Answers

Get a List of the declared objects in a class 1 Answer

[solved] Problem getting data from array 0 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