Skip to content

Evidence Randomization

Eruruw edited this page Mar 27, 2024 · 2 revisions

All evidence items in the scene are randomized and instantiated at runtime using a script.

Create Instances

Screenshot (188)

This is the main driver function for the evidence randomization. It compares the current number of evidence instances to the minimum and maximum number of evidence instances. If the number is below the minimum, it creates an instance 100% of the time. If the number is between the minimum and maximum, it creates an instance 60% of the time. Since the for loop runs the same amount as the max instances, that number will never be crossed. It should be noted that the true maximum is whatever the maxInstances variable is set to, minus one.

Get Random Prefab Index

Screenshot (189)

This function is how the script determines what prefab to spawn in. It creates a list with numbers correlating to however many prefabs are set in the inspector. It checks to see what prefabs have already been chosen to spawn in before choosing another index. After choosing the index of the prefab to be spawned in, it removes that index from the possible outcomes to avoid repetition.

Spawn Object

Screenshot (190)

This function is how the script determines where the prefab is spawned. It creates random values in between the bounds of the trigger area set in the scene. These values correspond to the x, y, and z coordinates in world space. This is where the prefab instance will be spawned in. After, it waits a short delay before randomizing the rotation of the object. In this manner, all objects spawned in have a random orientation when perceived in the game.

Clone this wiki locally