냥캣 소스

스크립트가 사방에 분포해있어서 보기 힘들지도..

 
다운로드

 

GameController.cs

게임 총괄 소스

using UnityEngine; 
using System.Collections; 
using UnityEngine.SceneManagement; 
 
public class GameController : MonoBehaviour { 
    //controller 
    public static GameController controller = null; 
 
    //boolean 
    public bool ready = true; 
    public bool isOver = false; 
 
    //prefab 
    public GameObject obstructions; 
    public GameObject saw; 
 
    //objects 
    public GameObject gameOverImg; 
    public GameObject window; 
    public GameObject retry; 
    public GameObject Player; 
    public GameObject Floor; 
    public GameObject bestImg; 
    public GameObject clicktostart; 
 
    //texts 
    public TextMesh score; 
    //public TextMesh finalScoreText; 
    public TextMesh bestScoreText; 
 
    // Use this for initialization 
    void Start () { 
         
  } 
    void OnEnable() 
    { 
        controller = this; 
    } 
   
  // Update is called once per frame 
  void Update () { 
      if(Input.GetMouseButtonDown(0) && ready ==true) 
        { 
            ready = false; 
            Destroy(clicktostart); 
            InvokeRepeating("createObs",1.0f, 2.5f); 
        } 
        else if(!ready && isOver && Input.GetKeyDown(KeyCode.Escape)) 
        { 
            SceneManager.LoadScene(0); 
        } 
  } 
 
    void createObs() 
    { 
        int x = Random.Range(0, 2); 
 
        if (x == 0) 
        { 
            Instantiate(obstructions); 
        } 
        else 
        { 
            Instantiate(saw); 
        } 
 
    } 
 
    public void gameOver() 
    { 
        if(isOver) 
        { 
            return; 
        } 
        isOver = true; 
        backgroundScroll.bkctl.isstop = true; 
         
        CancelInvoke("createObs"); 
        iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("x", 0.2, "y", 0.2, "time", 0.5f)); 
        iTween.MoveTo(gameOverImg, iTween.Hash("y", 1, "delay", 1.3f, "time", 0.5f)); 
        iTween.MoveTo(window, iTween.Hash("y", 0.1, "delay", 1.3f, "time", 0.5f)); 
        iTween.MoveTo(retry, iTween.Hash("y", -1, "delay", 1.3f, "time", 0.5f)); 
        if (GlobalVar.count > PlayerPrefs.GetInt("Best")) 
        { 
            PlayerPrefs.SetInt("Best", GlobalVar.count); 
            iTween.FadeTo(bestImg, iTween.Hash("alpha", 255, "time", 0.5f)); 
             
        } 
 
        //finalScoreText.text = GlobalVar.count.ToString(); 
        bestScoreText.text = PlayerPrefs.GetInt("Best").ToString(); 
        Player.GetComponent<Rigidbody>().useGravity = true; 
        Floor.GetComponent<BoxCollider>().isTrigger = true; 
 
        this.GetComponent<AudioSource>().Play(); 
 
         
 
    } 
 
    public void getScore() 
    { 
        if (!controller.isOver) 
        { 
            GlobalVar.count++; 
            Debug.Log(GlobalVar.count); 
            score.text = GlobalVar.count.ToString(); 
        } 
    } 
}