[英]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.