Skip to content

Instantly share code, notes, and snippets.

@kihira
Created October 18, 2015 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kihira/c83b995566ed75753ea8 to your computer and use it in GitHub Desktop.
Save kihira/c83b995566ed75753ea8 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using Image = UnityEngine.UI.Image;
public class EventHandlerUI : MonoBehaviour {
public GameObject bulletPrefab;
public Color pausedColor;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void GunButtonClick()
{
// Grab our player plane and create a copy of the bullet from the prefab
var plane = GameObject.FindWithTag("Player");
var bullet = Instantiate(bulletPrefab, plane.transform.position, plane.transform.rotation) as GameObject;
// Tell the physics engine to ignore collision between the bullet and our plane
Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), plane.GetComponent<Collider2D>());
// Destroy the bullet after 1 second (basically once it leaves the scene)
Destroy(bullet, 1f);
}
public void MissileButtonClick()
{
Debug.Log("Pew pew pew");
}
public void NukeButtonClick()
{
GameObject.Find("Score").GetComponent<ScoreManager>().AddScore(1000);
Debug.Log("Pew pew pew");
}
public void GearButtonClick()
{
// If time scale is greater then 0, that means its running so we need to pause
if (Time.timeScale > 0)
{
// Set timescale to 0 to prevent the game from running and set the image that is part of the canvas to semi opaque
Time.timeScale = 0;
gameObject.GetComponent<Image>().color = pausedColor;
Debug.Log("Game paused");
}
else
{
// Set timescale to 1 to allow the game to run at normal speed and set the image that is part of the canvas to transparent
Time.timeScale = 1;
gameObject.GetComponent<Image>().color = Color.clear;
Debug.Log("Game Resumed");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment