简体   繁体   English

在 Unity 中触摸 3d object 时,如何使 int go 加一

[英]How do I make an int go up by one when a 3d object is touched in Unity

I'm trying to make a game in which when a GameObject is touched by the player, it disappears until the next GameObject of that type is collected, and you earn a currency, in this case being an integer. All of the tutorials I've seen don't work at all.我正在尝试制作一个游戏,其中当玩家触摸一个游戏对象时,它会消失,直到收集到下一个该类型的游戏对象,并且您可以获得一种货币,在这种情况下是 integer。我的所有教程已经看到根本不起作用。 (Possibly because I'm using an older version of Unity and C#, Unity 2017.1.0f3 and C# 4, but I really don't want to upgrade.) And most of everything else talks about the act of physically touching the screen. (可能是因为我使用的是旧版本的 Unity 和 C#、Unity 2017.1.0f3 和 C# 4,但我真的不想升级。)其他大部分内容都与物理触摸屏幕的行为有关。

You can use colliders to detect a collision.您可以使用对撞机来检测碰撞。 This would require a collider and a rigidbody to be attached to the object(s).这将需要一个碰撞器和一个刚体连接到物体上。 Then you should be able to use the OnCollisionEnter function in the objects script to detect the collision.然后您应该能够在对象脚本中使用 OnCollisionEnter function 来检测碰撞。

void OnCollisionEnter(){
   i++;
}

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

相关问题 带有 Unity 3D 的 C#:当用户移动鼠标时,如何让相机围绕对象移动 - C# with Unity 3D: How do I make a camera move around an object when user moves mouse 当玩家 object 在一个统一的 3d 游戏中变得更大时,如何让相机移动 position? - How do I make the camera move position as the players object becomes bigger in a unity 3d game? 如何在 Unity 中的 SkinnedMesh 对象上制作 3D 边界框? - How do I make a 3D bounding box on a SkinnedMesh object in Unity? 如何为 3d 模型统一制作序列化字典? - How do I make a serialized dictionary in unity for 3d models? 如何在 Unity 2D 中旋转 object,然后在该方向旋转 go? - How do I rotate an object in Unity 2D and then go in that direction? 当被光线触碰时,Unity会使物体褪色 - Unity make object fade when touched by light Unity 3D。 当另一个物体到达上面时,如何向上移动该物体 - Unity 3D. How do I move the object up when the another object gets on it 如何使用 Unity 3D 中的 A 和 D 键使播放器 object 旋转? - How can I make a Player object rotate using the A and D keys in Unity 3D? 在 Unity 中与游戏对象发生碰撞时,如何让我的玩家加速? - How do I make my player speed up when collide with a game object in Unity? Unity 3D - 如何全局旋转一个 object 基于秒 - Unity 3D - How to gllobaly rotate one object based on second
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM