• 是男人就下一百层代码


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class GameManage : MonoBehaviour {
        private Image bg;
        private GameObject[] clouds;
        private GameObject[] awards;
        private Transform gameCanvas;
        private int count;
        public Text Count;
        // Use this for initialization
        void Start () {
            bg = GameObject.Find("BG").GetComponent<Image> ();
            clouds = Resources.LoadAll<GameObject> ("clouds");
            awards = Resources.LoadAll<GameObject> ("Awards");
            gameCanvas = GameObject.Find ("GameCanvas").transform;
            InvokeRepeating ("CreateAll", 0, 1);
            count = 0;
        }
    
        // Update is called once per frame
        void Update () 
        {
            
            bg.material.SetTextureOffset ("_MainTex", new Vector2 (0, Time.time / 5)); 
            Count.text = "层数" + count.ToString ();
        }
        private void CreateAll() //生成云和物品
        {
            int rangeNum = Random.Range (0,5);
            GameObject tempObject = null;
            if (0 == rangeNum) 
            {
                tempObject = clouds [3];
            } 
            else 
            {
                tempObject = clouds [Random.Range (0, clouds.Length - 1)];
            }
    
            GameObject clude = Instantiate (tempObject, new Vector3 (Random.Range(-340,341),-800,0), Quaternion.identity);
            clude.transform.SetParent (gameCanvas, false);
            GameObject award = CreateAward ();
            if (award != null) 
            {
                Instantiate (award,new Vector3(0,40,0),Quaternion.identity).transform.SetParent (clude.transform,false);
            }
            clude.AddComponent<CloudsMove> ();
            count++;
    
        }
        private GameObject CreateAward()
        {
            int num = Random.Range (0, 9);
            GameObject temp = null;
            if (0 == num)
            {
                temp = awards [1];
            } 
            else if (0 < num && num < 4) 
            {
                temp = awards [0];
            } 
            else 
            {
                temp = null;
            }    
            return temp;
        }
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class CloudsMove : MonoBehaviour {
    
        // Use this for initialization
        void Start () {
    
        }
    
        // Update is called once per frame
        void Update () {
            transform.Translate (Vector3.up * Time.deltaTime * 3);
        }
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class PlayerControl : MonoBehaviour {
        //private Animator ani;
        private int life;
        private int grade;
    
        public Text Lift;
        public Text Grade;
    
        // Use this for initialization
        void Start () {
            //ani = GetComponent<Animator> ();
            life = 1;
            grade = 0;
    
        }
        
        // Update is called once per frame
        void Update () 
        {
            if (Mathf.Abs (transform.localPosition.y) >= 800) 
            {
                life--;
                transform.localPosition = new Vector3 (0, 600, 0);
            }
            if (life <= 0)
                UnityEditor.EditorApplication.isPlaying = false;
            Move ();
            Lift.text = "生命" + life.ToString ();
            Grade.text = "分数" + grade.ToString ();
    
        }
        private void Move()
        {
            float h = Input.GetAxis ("Horizontal");
            if (Mathf.Abs (h) > 0.1f)
            {
                if (h > 0)
                    transform.localRotation = Quaternion.Euler (0, 0, 0);
                else
                    transform.localRotation = Quaternion.Euler (0, 180, 0);
                
                transform.Translate (h * transform.right * 5*Time.deltaTime);
            }
        }
        public void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == "Gold") 
            {
                grade += 10;
            } 
            else if (other.tag == "Life") 
            {
                life+=1;
            }
            Destroy (other.gameObject);
        }
    }
  • 相关阅读:
    Swift语言快速入门
    软件测试工程师成长之路:掌握软件测试九大技术主题
    Swift语言快速入门
    python学习笔记之——python模块
    python学习笔记之——python函数
    python学习笔记之—— calendar(日历)模块
    python的学习笔记之——time模块常用内置函数
    python学习笔记之——range()函数
    robotframework的学习笔记(十六)----robotframework标准库String
    robotframework的学习笔记(十五)----robotframework标准库Collections
  • 原文地址:https://www.cnblogs.com/xisheng/p/10986691.html
Copyright © 2020-2023  润新知