码迷,mamicode.com
首页 > 其他好文 > 详细

是男人就下一百层代码

时间:2019-06-06 21:04:52      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:this   image   ant   ons   orm   color   eof   engine   load   

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);
    }
}

 

是男人就下一百层代码

标签:this   image   ant   ons   orm   color   eof   engine   load   

原文地址:https://www.cnblogs.com/xisheng/p/10986691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!