Adding anchors at random locations

We want to create a new anchor node randomly every few seconds, and by using the crosshair we should be able to center the crosshair on the virtual 3D object and tap the screen to remove the virtual object from the scene. We will then track the score to see how many virtual objects are left in the scene.

At the top of the Scene class, create two new variables of type timeInterval and Int called creationTime and score, and initialize both of them to 0:

    var creationTime: TimeInterval = 0
    var score: Int = 0

Also add a new function called randomFloat, which will take in a minimum and maximum float value and generate a random float value between the maximum and minimum values:

 func randomFloat(min: Float, max: Float) ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.