是男人就下一百层代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManage : MonoBehaviour {
    private Image bg;
    private GameObject[] clouds;
    private GameObject[] award;
    private Transform gameCanvas;
    // Use this for initialization
    void Start () {
        bg = GameObject.Find("BG").GetComponent<Image> ();
        clouds = Resources.LoadAll<GameObject> ("clouds");
        award = Resources.LoadAll<GameObject> ("Award");
        gameCanvas = GameObject.Find ("GameCanvas").transform;
        InvokeRepeating ("CreateAll", 0, 1);
    }
    
    // Update is called once per frame
    void Update () {
        bg.material.SetTextureOffset ("_MainTex", new Vector2 (0, Time.time / 5)); 

    }
    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,20,0),Quaternion.identity).transform.SetParent (clude.transform,false);
        }
        clude.AddComponent<CloudsMove> ();

    }
    private GameObject CreateAward()
    {
        int num = Random.Range (0, 9);
        GameObject temp = null;
        if (0 == num)
        {
            temp = award [1];
        } 
        else if (0 < num && num < 4) 
        {
            temp = award [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);
    }
}

 

上一篇:用函数式编程,从0开发3D引擎和编辑器(三):初步需求分析


下一篇:unity学习(二)GameObject