美文网首页
VR开发实战之MortalBarrenLand(致命荒岛)

VR开发实战之MortalBarrenLand(致命荒岛)

作者: TonyWan_AR | 来源:发表于2017-01-13 13:42 被阅读112次

    框架视图

    关键代码

    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()
        {//要注意协同程序返回值类型
            //等待一秒后执行;
            yield return new WaitForSeconds(1f);//协同程序返回值格式 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);
            //等待一秒后执行;
            yield return new WaitForSeconds(1f);//协同程序返回值格式 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();//参数1:游戏对象 参数2:之前设置打开动画的名称 字符串格式
    
        //}
    
    
        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);
        }
        //记录状态
    
        private bool isOpen;
    
        //点击宝箱事件
        public void ChestClicked() {
    
    
            if (isOpen)
            {
                //关闭事件
                iTweenEvent.GetEvent(gameObject,"CloseChest").Play();
                //设置布尔值;
                isOpen = false;
                //返回之后,不再执行以下事件;
                //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();//参数1: 游戏对象 参数2: 设置动画的名称;
            //重置布尔值;
            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();//参数1:游戏对象 参数2:之前设置打开动画的名称 字符串格式
    
        }
    
    
    

    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("按下的数是:" + 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 {
    
        //旋转事件
        public void RoateSelf() {
    
          //  gameObject.transform.Rotate(Vector3.up,10.0f);
            Debug.Log("旋转");
        }
    
    }
    

    相关文章

      网友评论

          本文标题:VR开发实战之MortalBarrenLand(致命荒岛)

          本文链接:https://www.haomeiwen.com/subject/zccsbttx.html