Day 68 — Implementing a Coin Distraction Ability Part 1

public GameObject coinPrefab;
public AudioClip coinSoundEffect;
private bool _coinThrown = false;
void Update()
{
if (Input.GetMouseButtonDown(1) && _coinThrown == false)
{
Ray rayOrigin = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(rayOrigin, out hitInfo))
{
_coinThrown = true;
Instantiate(coinPrefab, hitInfo.point, Quaternion.identity);
AudioSource.PlayClipAtPoint(coinSoundEffect, hitInfo.point);
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Connor Fullarton

Connor Fullarton

59 Followers

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.