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 NinjaRubberBand · Oct 04, 2015 at 08:09 PM · c#destroy

Destroy specific object with tag

I have this in my script:

void OnTriggerEnter(Collider other) { if(other.tag == "Dead") { }

I want to destroy that object im touching with the tag "Dead". But not destroy all Object with tag Dead. Something like: Destroy(Other.tag = "Dead");

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bubzy · Oct 04, 2015 at 09:37 PM

that should only destroy the object that you collide with.

Destroy(other.gameObject);

should work for you

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 $$anonymous$$ · Oct 06, 2015 at 08:36 AM

I'm having similar problems. I got health on target. But I hit the target and the bullets bounce off. in order to get the bullet clones to go away I already added a destroy script to the bullet. If i try and change this, it stops working. But then again aside from stopping being able to actually "Shoot" and self destruct, any changes I made to the code causes it to stop working all together and gives me a bunch of errors.

public class MoveBullet : MonoBehaviour {

 public float speed = 1.0f;

   
 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
     transform.Translate(0, 0, speed);
   
     Destroy(gameObject, 6); //<===This only works to make the bullet go away ===
     
     }

 }

Enemy health is as follows and while there are no "errors" nothing actually happens to the enemy target.

public class Health : MonoBehaviour {

 public float health = 100f;
 public void RemoveHealth(float amount)
 {
 health = health - amount;

     if (health <= 0) { Destroy(gameObject); }
 } 
 void Start()
 {
 }

}

The shooting script is as follows and each time I try and modify it any further, it stops working.

public class Shoot : MonoBehaviour { public GameObject bullet; public float delayTime = 1;

 private float counter = 0;
  
 void Start()
 {
 }

 void Update()
 {

     if (Input.GetKey(KeyCode.Mouse0) && counter > delayTime)
     {
         Instantiate(bullet, transform.position, transform.rotation);
         GetComponent<AudioSource>().Play();
         counter = 0;
     }
     counter += Time.deltaTime;
 }

}

Enemy Following Script as Enemy_AI works but the same problem occurs where if i try and modify it, it stops working. On top of that, NO Enemy Spawn script will even add without a bunch of errors.

public class Enemy_AI : MonoBehaviour {

 Transform tr_Player;
 float f_RotSpeed = 3.0f, f_MoveSpeed = 3.0f;



 // Use this for initialization
 void Start () {

     tr_Player = GameObject.FindGameObjectWithTag("Player").transform;

     }

 // Update is called once per frame
 void Update () {
     transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(tr_Player.position - transform.position), f_RotSpeed * Time.deltaTime);
     transform.position += transform.forward * f_MoveSpeed * Time.deltaTime;

 }

}

No solutions seem to be forthcoming especially any tutorials showing the usage of the Visual Studio or anything with current instructions that are not constantly failing codes. It's really irritating that after spending 4 weeks just to get to this point to not be able to spawn enemies, or destroy them and i haven't even bothered trying to work on getting enemies to shoot back or take damage.

It makes things really frustrating to say the least all the references I get sent to is incompatible with the current engine, which is 5.2 and nothing of any use by way of tutorial videos for 2015, and now needed for 2016 in just a couple of months. If you have solved any of these things "PLEASE" help!!!

Understand I am very new to coding and only tried to do stuff a few years back before giving up. The fact I even managed to get this far with static objects (not having any success with humanoid avatars I made with "MakeHuman" which always get's messed up upon Import and no instructions are of any help).

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 $$anonymous$$ · Oct 05, 2015 at 06:02 PM 0
Share

PS. All targets i want to destroy are tagged "Enemy." I really doubt what was being asked was to simply "destroy any object" in a scene, like for example, the terrain. Just the intended targets.

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

30 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

Related Questions

I need to make a Sphere appear 15 seconds after the FPSController has collided with a Cube and then make the Cube disappear after 30 seconds. 1 Answer

C# float variable isnt behaving like its value 1 Answer

Destroyed instance of Prefab, can't spawn it back. 1 Answer

How do I destroy a GameObject/Script that instantiates other objects, without destroying the objects it has previously instantiated? 0 Answers

creating a Breakout game in unity3d c#-bricks wont get destroyed 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