简体   繁体   中英

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. (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.

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.

void OnCollisionEnter(){
   i++;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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