using UnityEngine;
using System.Collections;
public class Rock : MonoBehaviour {
// Use this for initialization
void Start () {
// Rock => Polygon Colloder 2D.
// Airplane => Circle Colloder 2D. Not Polygon Colloder 2D.
Destroy(this.gameObject, 5f);
}
// Update is called once per frame
void Update () {
transform.Translate (Vector2.left * 5 * Time.deltaTime);
}
}
//////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
public class BlockExit : MonoBehaviour {
// onCollisionExit2D
void onCollisionExit2D(Collision2D coll) {
if (coll.gameObject.tag == "BLOCK") {
GM.isGameOver = true;
print ("Game Over....!!");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
///////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
public class groundColl : MonoBehaviour {
// 1
void onCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "BLOCK") {
GM.isGameOver = true;
print ("Game Over.!");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
//////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
public class BlockMove : MonoBehaviour {
Rigidbody2D rigidbody2d = null;
bool isRight = true;
// Use this for initialization
void Start () {
rigidbody2d = GetComponent<Rigidbody2D>();
rigidbody2d.gravityScale = 0;
}
// Update is called once per frame
void Update () {
if (GM.isTouch) {
rigidbody2d.gravityScale = 1;
GM.isTouch = false;
enabled = false;
}
Move ();
}
void Move() {
if (this.transform.position.x < -3) {
isRight = true;
} else if (this.transform.position.x > 3) {
isRight = false;
} else {
Debug.Log ("X 이동 범위 에러.");
}
if (isRight) {
this.transform.Translate (Vector2.right * GM.speed * Time.deltaTime, Space.World);
} else {
this.transform.Translate (-Vector2.right * GM.speed * Time.deltaTime, Space.World);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
public class CameraCtrl : MonoBehaviour {
Vector3 cameraY = new Vector3( 0.0f, 1.5f, 0.0f );
void onTriggerEnter2D(Collider2D coll) {
if (coll.gameObject.tag == "BLOCK") {
this.transform.position += cameraY;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (GM.isGameOver) {
StartCoroutine (ZoomOut ());
}
}
IEnumerator ZoomOut() {
for (int i = 5; i < GM.score * 3; i++) {
yield return new WaitForSeconds (0.01f);
GetComponent<Camera>().orthographicSize = i;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GM : MonoBehaviour {
static public bool isTouch = false;
static public bool isGameOver = false;
static public float speed = 5;
static public int score = 0;
public GameObject[] blockPrefab = null;
public GameObject replayBtn = null;
public Text scoreText = null;
public AudioClip btnSound = null;
int blockcolor = 0;
float blockY = 1.5f;
// Use this for initialization
void Start () {
isGameOver = false;
speed = 5;
score = 0;
}
// Update is called once per frame
void Update () {
// !isTouch && !isGameOver
if (Input.anyKeyDown) {
if (isTouch == false && isGameOver == false) {
isTouch = true;
StartCoroutine (BlockCreate ());
}
}
if (isGameOver) {
replayBtn.SetActive (true);
}
}
IEnumerator BlockCreate() {
yield return new WaitForSeconds (0.5f);
Instantiate(blockPrefab[blockcolor],new Vector2(0, blockY), Quaternion.identity);
speed += 0.5f;
score++;
blockcolor++;
blockY += 1.5f;
if (blockcolor > 4) {
blockcolor = 0;
}
scoreText.text = "SCORE : " + score.ToString ();
}
public void Replay() {
GetComponent<AudioSource> ().clip = btnSound;
GetComponent<AudioSource> ().Play ();
SceneManager.LoadScene ("2D1");
//Application.LoadLevel ("2D1");
print("New Game");
}
}
////////////////////////////////////////////////////////////////////////
연습 연습..!
'문서 모음' 카테고리의 다른 글
CreateTrayIcon / DeleteTrayIcon (0) | 2017.01.25 |
---|---|
유니티 연습.! (0) | 2016.10.15 |
Unity 4 => Unity 5 로 바끼면서 수정된 부분.! (0) | 2016.09.26 |
기본적인 족보 관련 디파인.!120.! (0) | 2016.08.16 |
머리패 검사후.! (0) | 2016.08.12 |