Game Development Reference
In-Depth Information
Creating player interactions
Here, we will create ways for the player to interact with the game world. For our game,
we will have the player shooting their gun, collecting potions, and pausing the game
as interactions. Create a new C# script and name it PlayerInteraction . First, we
will create a couple of variables and add them to our script:
public GameObject Projectile, Potion;
The Projectile GameObject will be the bullets that we shoot and the Potion
GameObject will be the potion prefab that we created earlier.
Shooting and pausing
We will create the functionality to shoot the gun and pause the game. Add this Up-
date function to your script:
void Update ()
{
if(Time.tmeScale != 0.00f)
{
if(Input.GetButtonUp("Fire1"))
Instantiate(Projectile, transform.position,
transform.rotation);
if(Input.GetButtonUp("Esc_Key"))
{
if(Time.timeScale != 0.00f)
Time.timeScale = 0.00f;
else
Time.timeScale = 1.00f;
}
}
}
Search WWH ::




Custom Search