Make a coin

The coin object

  1. In the Hierarchy, select + and choose 3D Object ▸ Cylinder. Rename it Coin.
  2. Set its Rotation to 90, 0, 0 and its Scale to 1, 0.1, 1. The cylinder is now a flat disc standing on its edge.
  3. Drag Gold.mat onto Material 0 in its MeshRenderer.
  4. Add a BoxCollider and select isTrigger. A trigger collider notices what passes through it instead of blocking it, so the player can run into the coin and pick it up.

The Coin component

  1. Select Scripts ▸ New C++ Component..., enter Coin as the Class name and select Create.
  2. Replace the contents of the two new files:
Source/Coin.h
#pragma once

#include "Shalltear.h"

// a coin the player can collect. It spins so it catches the eye; the player
// is what notices the touch and collects it (PlayerController)
class Coin : public Behavior {
public:
	Coin() : Behavior(BehaviorTick::Update) {}

	SLT_REFLECT_COMPONENT(Coin, Behavior)
	SLT_REFLECT_FIELD(value)
	SLT_REFLECT_FIELD(degreesPerSecond)
	SLT_END_REFLECT()

	// how many coins this one counts as
	i32 value = 1;
	f32 degreesPerSecond = 90.0f;
protected:
	void OnUpdate() override;
};
Source/Coin.cpp
#include "Coin.h"

SLT_REGISTER_TYPE(Coin)

void Coin::OnUpdate() {
	SceneObject* object = GetOwner().Get();
	if (!object) {
		return;
	}
	// the step goes on the LEFT, which turns the coin about the world's up
	// axis. The coin is tipped on its edge, so its own up axis points sideways
	// and a step on the right would roll it instead
	const Quat step = Quat::AngleAxis(degreesPerSecond * Time::GetDeltaTime(), Vec3::Up());
	object->SetLocalRotation((step * object->GetLocalRotation()).Normalized());
}
  1. Save both files. The editor compiles them, and Coin appears in Add Component.
  2. Select the coin and add the Coin component.

A prefab, placed five times

A prefab is an object saved as an asset, so you can place copies of it that all follow the saved original.

  1. Drag the Coin row from the Hierarchy onto the Asset Browser. The editor saves it as Coin.prefab, and the coin in the scene becomes a copy of it.
  2. Drag Coin.prefab from the Asset Browser into the Scene View four times, so the level has five coins.
  3. Set each coin's Position:
CoinPosition
1-5, 0.75, 5
25, 0.75, 5
30, 0.75, 6
4-5, 0.75, -5
55, 0.75, -5

Press Ctrl+P to play. The coins spin; press Ctrl+P again to stop. To change every coin at once later, double-click Coin.prefab to edit the prefab itself.

Save the scene. Next, move the player.