Toss A Coin To Your W-… Security Guard. (Part 1)

Today I’m giving the player’s character, a thief, the ability to toss a coin to distract the security guards, moving them to another location.

Vincent Taylor
2 min readNov 9, 2021
(In part 3, I will fix the spontaneous appearance which I don’t like.)

Today’s Objective: Create the coin toss ability, making a coin spawn at the position the player right-clicks at.

The Code:

In my previously created “PlayerControl” class, I will add the variables needed for this ability:

In Update( ), I add a check for the right mouse button click:

The TossCoin( ) method is a coroutine so that I can have delays between code executions for the event.

As for the actual coin toss code, it is as follows, and goes in the position marked above:

Find position -> animate -> spawn -> audio -> destroy

And that’s it for the coin toss ability itself!

Now obviously this doesn’t make the guards aware of it. I will cover that in my next post, Part 2.

I will also be working on making the coin toss an actual toss, rather than a spontaneous appearance, in Part 3.

Thanks for reading! Stay tuned for the following parts in the next 2 days!

--

--

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.