框架視圖
關(guān)鍵代碼
Boom
using UnityEngine;
using System.Collections;
public class Boom : MonoBehaviour {
public GameObject B1;
public GameObject B2;
public GameObject B3;
private GameObject m_B1;
private GameObject m_B2;
private GameObject m_B3;
// public GameObject m_Canvas;
void Start()
{
// m_Canvas.SetActive(false);
//B1.SetActive(false);
//B2.SetActive(false);
//B3.SetActive(false);
StartCoroutine("Task");
}
IEnumerator Task()
{//要注意協(xié)同程序返回值類型
//等待一秒后執(zhí)行;
yield return new WaitForSeconds(1f);//協(xié)同程序返回值格式 yield return
m_B1 = GameObject.Instantiate(B1, gameObject.transform.position+new Vector3(-10,13,-4f), Quaternion.identity) as GameObject;
m_B1.SetActive(true);
m_B2 = GameObject.Instantiate(B2, gameObject.transform.position + new Vector3(0,10, 0f), Quaternion.identity) as GameObject;
m_B2.SetActive(true);
m_B3 = GameObject.Instantiate(B3, gameObject.transform.position + new Vector3(8, 7, -4f), Quaternion.identity) as GameObject;
m_B3.SetActive(true);
//等待一秒后執(zhí)行贰逾;
yield return new WaitForSeconds(1f);//協(xié)同程序返回值格式 yield return
GameObject.Destroy(gameObject);
}
void Update () {
}
}
ChestMgr
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ChestMgr : MonoBehaviour {
//點擊寶箱事件
//public void ChestClicked() {
//動畫事件獲取某個事件 然后播放
// iTweenEvent.GetEvent(gameObject,"OpenChest").Play();//參數(shù)1:游戲?qū)ο?參數(shù)2:之前設(shè)置打開動畫的名稱 字符串格式
//}
public Text m_text;
private float time = 20f;
private bool boomOpen = false;
public GameObject B1;
public GameObject B2;
public GameObject B3;
public GameObject m_Canvas;
public GameObject Texture;
private GameObject m_Texture;
void Start() {
m_Texture = GameObject.Instantiate(Texture)as GameObject;
m_Canvas.SetActive(false);
B1.SetActive(false);
B2.SetActive(false);
B3.SetActive(false);
}
//記錄狀態(tài)
private bool isOpen;
//點擊寶箱事件
public void ChestClicked() {
if (isOpen)
{
//關(guān)閉事件
iTweenEvent.GetEvent(gameObject,"CloseChest").Play();
//設(shè)置布爾值悬荣;
isOpen = false;
//返回之后,不再執(zhí)行以下事件疙剑;
//m_Texture.transform.Translate(new Vector3(m_Texture.transform.position.x-6.8f, m_Texture.transform.position.y+5, m_Texture.transform.position.z+25));
return;
}
//打開寶箱事件
//動畫播放事件 獲取某個事件 然后播放氯迂;
iTweenEvent.GetEvent(gameObject,"OpenChest").Play();//參數(shù)1: 游戲?qū)ο?參數(shù)2: 設(shè)置動畫的名稱;
//重置布爾值言缤;
isOpen = true;
m_Texture.transform.Translate(new Vector3(m_Texture.transform.position.x-8f, m_Texture.transform.position.y+10f,m_Texture.transform.position.z+13));
//炸彈計時:
boomOpen = true;
m_Canvas.SetActive(true);
}
void Update()
{
if (boomOpen)
{
time -= Time.deltaTime;
m_text.text = "" + time;
if (time<=0)
{
m_Canvas.SetActive(false);
B1.SetActive(true);
B2.SetActive(true);
B3.SetActive(true);
GameObject.Destroy(GameObject.FindGameObjectWithTag("Boom"));
//退出游戲
// SceneManager.LoadScene(0);
Application.Quit();
Debug.Log("退出游戲嚼蚀!");
}
}
}
}
CreateChest
using UnityEngine;
using System.Collections;
public class CreateBoxes : MonoBehaviour
{
// Use this for initialization
public GameObject pre;
void Start()
{
CreateWall();
}
// Update is called once per frame
void Update()
{
}
void CreateWall()
{
for (int i = -9; i < -1; i += 2)
{
for (int j = 10; j < 16; j++)
{
// GameObject.Instantiate(prefabBrick,new Vector3(i,j,2),Quaternion.identity);
GameObject.Instantiate(pre, new Vector3(i, -9.04f, j), Quaternion.Euler(0,180,0));
}
}
}
}
keyMgr
using UnityEngine;
using System.Collections;
public class keyMgr : MonoBehaviour {
public void keyClicked() {
iTweenEvent.GetEvent(gameObject, "setKey1").Play();//參數(shù)1:游戲?qū)ο?參數(shù)2:之前設(shè)置打開動畫的名稱 字符串格式
}
keys
using UnityEngine;
using System.Collections;
public class keys : MonoBehaviour {
public void IsSetActive() {
gameObject.SetActive(false);
}
}
LockCode
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LockCode : MonoBehaviour {
public string str = "";
private GameObject MDoor;
void Start () {
}
void Update () {
}
public void GetCodeLock(string str1) {
switch(str1){
case "0": str += str1;
break;
case "1": str += str1;
break;
case "2": str += str1;
break;
case "3": str += str1;
break;
case "4": str += str1;
break;
case "5": str += str1;
break;
case "6": str += str1;
break;
case "7": str += str1;
break;
case "8": str += str1;
break;
case "9": str += str1;
break;
case "clear": str = "";
break;
case "confirm": if (str == "0113")
{
Debug.Log("collect");
MDoor = GameObject.FindGameObjectWithTag("MainDoor");
// MDoor.transform.Rotate(Vector3.up,100f);
SceneManager.LoadScene(3);
break;
}
else {
str = "";
Debug.Log("errom"+str);
break;
};
default:
break;
}
Debug.Log("按下的數(shù)是:" + str);
}
}
TestButtonClick
using UnityEngine;
using System.Collections;
public class TestButtonClick : MonoBehaviour {
//方法:
public void TestClick() {
string str = gameObject.name;
Debug.Log(str);
string str1 = "";
switch (str)
{
case "btn0": str1 = 0+"";
break;
case "btn1": str1 = 1 + "";
break;
case "btn2": str1 = 2 + "";
break;
case "btn3": str1 = 3 + "";
break;
case "btn4": str1 = 4 + "";
break;
case "btn5": str1 = 5 + "";
break;
case "btn6": str1 = 6 + "";
break;
case "btn7": str1 = 7 + "";
break;
case "btn8": str1 = 8 + "";
break;
case "btn9": str1 = 9 + "";
break;
case "clear": str1 = "clear";
break;
case "confirm": str1 = "confirm";
break;
default:
break;
}
gameObject.SendMessageUpwards("GetCodeLock",str1);
}
}
TestRoate
using UnityEngine;
using System.Collections;
public class TestRoate : MonoBehaviour {
//旋轉(zhuǎn)事件
public void RoateSelf() {
// gameObject.transform.Rotate(Vector3.up,10.0f);
Debug.Log("旋轉(zhuǎn)");
}
}