简体   繁体   English

Unity 3D - 点击鼠标摧毁游戏对象

[英]Unity 3D - Destroy a gameobject with a click on mouse

I have three prefabs that I want to destroy with a click.我有三个想要通过单击破坏的预制件。 The name of the prefabs are blue, green and red.预制件的名称是蓝色、绿色和红色。 When I click on red, I destroy it, later, I click on green and he is destroyed and finally I click on blue and he is destroyed too.当我点击红色时,我将它摧毁,然后,我点击绿色,他被摧毁,最后我点击蓝色,他也被摧毁。 The problem is when I click on Blue Firstly, all prefabs are destroyed.问题是当我点击 Blue First 时,所有预制件都被破坏了。 If I click on green firstly, green and red are destroyed.如果我先点击绿色,绿色和红色就会被破坏。 I know that they are destroyed by alphabetical order but they are different gameobjects.我知道它们是按字母顺序销毁的,但它们是不同的游戏对象。 I named them with different tags but the problem is still continued.我用不同的标签命名它们,但问题仍然存在。 What is the problem?问题是什么? Thank You!谢谢你!

Putting a simple method for destruction on them should be enough.对它们施加简单的破坏方法就足够了。

void OnMouseDown()
{
    Destroy(gameObject);
}

Maybe your colliders are too big too.也许你的对撞机太大了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM