Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Domselbs · Dec 27, 2015 at 12:59 PM · inspectorcollidersdissapear

Collider is deleting itself when I press play

So I am working on a little "start-up" project where I am making my own game. I'm still relatively a beginner, and thought I'd try to make a little something :). It is basically a player jet flying through a little gorge trying to kill as many enemies as possible while trying to stay alive. But I have a problem with the enemy game object. For ease, I duped the Player "Plane" object and renamed it to "Enemy", and took out the script for the player game object, and added a new script that deals with the enemy movement and shooting. The player has a box collider, which I have coded correctly to interact with the enemy collider. But the enemy Box collider deletes itself when I hit play. What's more, the actual component in the inspector disappears as well. I am so confused as to why this is happening, and have tried everything I can to fix it. I even tried re-doing the whole enemy game object, and replacing it with a new object and code, but that didn't work. I have some player boundaries, but they only interact with the player, and to make sure that this is the case, I have made it so that only objects with the tag "Player" are affected. I have been trying to fix this for about a week and it is so annoying!!

Please help if u can, thanks in advance!

Here is the code(which is all fairly similar) I use for the enemy, the code for destroying the player, removing the shots, and for destroying the enemy

Enemy code:

 using UnityEngine;
 using System.Collections;
 
 public class EnemySortOut : MonoBehaviour
 {    
     
     public GameObject Shot;
     public Transform ShotSpawn;
     public float FireRate;
     public float ForwardPush;
 
     private float NextFire;
     private Rigidbody rb;
 
     void Start () 
     {    
         rb = GetComponent<Rigidbody> ();
     }
     
 
     void FixedUpdate () 
     {
         if (Time.time > NextFire) 
         {
             NextFire = Time.time + FireRate;
             Instantiate (Shot, ShotSpawn.position, ShotSpawn.rotation);
         }
 
         rb.velocity = (transform.forward * ForwardPush);
     }

 }

Destroying the player:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerDestroy : MonoBehaviour {
 
     public AudioSource PlayerDestroySound;
     public GameObject PlayerExplosion;
 
 
 
     void Start ()
     {
         PlayerDestroySound = GetComponent<AudioSource> ();
 
     }
 
 
     void OnTriggerEnter (Collider other) 
     {
         if (other.gameObject.tag == "Player") 
         {
             Instantiate (PlayerExplosion, other.transform.position, other.transform.rotation);
             PlayerDestroySound.Play ();
 
             Destroy (other.gameObject);
 
 
         }
 
     }
 }
 

Removing the shots:

 using UnityEngine;
 using System.Collections;
 
 public class ShotRemover : MonoBehaviour
 {
     void OnTriggerExit(Collider other)
     {    
         if (other.gameObject.tag == "Shot")
         {
             Destroy (other.gameObject);
         }
 
         if (other.gameObject.tag == "Player") 
         {
             other.gameObject.SetActive (false);
             other.gameObject.SetActive (true);
         }
     
     }
 
 }
 

Destroying the enemy:

 using UnityEngine;
 using System.Collections;
 
 public class EnemyDestroyer : MonoBehaviour 
 {
 
     public AudioSource EnemyDestroySound;
     public GameObject EnemyExplosion;
 
 
 
     void Start ()
     {
         EnemyDestroySound = GetComponent<AudioSource> ();
     
     }
     
     void OnTriggerEnter (Collider other) 
     {
         if (other.gameObject.tag == "Enemy") 
         {
             Instantiate (EnemyExplosion, other.transform.position, other.transform.rotation);
             EnemyDestroySound.Play ();
 
             Destroy (other.gameObject);
 
 
         }
 
 
 
     }
 
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

33 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

Related Questions

script for object to use its child colliders. 0 Answers

[SOLVED] Colliders aren't working properly. Clipping through ground. 1 Answer

What makes a collider trigger work and not work? 0 Answers

Character falls through the floor 1 Answer

Why i can't see scenes in inspector? 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