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 /
avatar image
0
Question by OrthorsOfficial · Jan 09, 2018 at 09:12 PM · triggerscollisions

How do I get my enemy to destroy my spaceship?

,Basically I have a spaceship and an enemy. When my spaceship comes in to contact with the enemy i want them to both be destroyed. However, whats happening is, the player is just going straight through the enemy.

Any solution would be greatly appreciated! :D (I've attached the scripts i used for both the enemy and the spaceship) alt text

screen-shot-2018-01-09-at-205718.png (77.4 kB)
screen-shot-2018-01-09-at-205710.png (47.1 kB)
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 pako · Jan 09, 2018 at 10:01 PM 0
Share

@OrthorsOfficial please post your code by clicking the "101010" button on the toolbar, ins$$anonymous$$d of images. This helps copy/paste when others modify your code to help you.

avatar image OrthorsOfficial pako · Jan 09, 2018 at 10:59 PM 0
Share

Oh ok great, thanks! Just done it

avatar image OrthorsOfficial OrthorsOfficial · Jan 09, 2018 at 10:59 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DestroyByContact : $$anonymous$$onoBehaviour 
 {
     void OnTriggerEnter(Collider other) 
     {
         if (other.tag == "Player") 
         {
             Destroy (other.gameObject);
             Destroy (gameObject);
         }
     }
 }
 
Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AcePilot10 · Jan 09, 2018 at 09:41 PM

A few things could be the issue here. For us to help you it would probably be useful to post a screenshot of your collider component. In the meantime make sure that your collider is set to IsTrigger (As you are checking for OnTriggerEnter). Also try some debugging like seeing if the collision is triggered by writing Debug.Log("Ship was hit") inside of your OnTriggerEnter function

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

Answer by OrthorsOfficial · Jan 09, 2018 at 09:59 PM

@AcePilot10 Hey thanks for the help. Ive just attached the screenshots. I tried adding in the "Debug" but I dont think anything is being triggered.alt text


screen-shot-2018-01-09-at-215624.png (104.2 kB)
screen-shot-2018-01-09-at-215617.png (118.2 kB)
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 OrthorsOfficial · Jan 09, 2018 at 10:58 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : $$anonymous$$onoBehaviour {
 
     public float speed;
     public float clockwise = 100.0f;
     public float counterClockwise = 5.0f;
 
     private Rigidbody2D rb2d;
 
     void Start ()
     {
         rb2d = GetComponent<Rigidbody2D> ();
     }
 
     void FixedUpdate ()
     {
         rb2d.transform.Translate (0, speed * Time.deltaTime, 0);
 
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A)) 
         {
             transform.Rotate (0, 0, Time.deltaTime * clockwise);
         } 
         else if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.S)) 
         {
             transform.Rotate (0, 0, -Time.deltaTime * counterClockwise);    
         }
     }
 }











avatar image OrthorsOfficial · Jan 09, 2018 at 10:58 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DestroyByContact : $$anonymous$$onoBehaviour 
 {
     void OnTriggerEnter(Collider other) 
     {
         if (other.tag == "Player") 
         {
             Destroy (other.gameObject);
             Destroy (gameObject);
         }
     }
 }
 

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

76 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

Related Questions

How do I prevent multiple triggers using OnTriggerEnter? 1 Answer

Ignore collisions with self but still trigger with self 2 Answers

colliding with child trigger? 0 Answers

OnTriggerEnter called much less often after a player respawn? 1 Answer

Colliders overlapping with trigger colliders 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