是男人就下一百层代码
作者:互联网
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); } }
标签:clouds,GameObject,代码,transform,award,private,using,一百,男人 来源: https://www.cnblogs.com/xisheng/p/10986691.html