首页 > 其他 > 详细

是男人就下一百层代码

时间:2019-06-06 20:21:45      阅读:73      评论:0      收藏:0      [点我收藏+]
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);
    }
}

 

是男人就下一百层代码

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!