1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CreateStone : MonoBehaviour {
- //创建单例
- public static CreateStone instance;
- private GameObject stone;
- private GameObject prop;
- private void Awake()
- {
- instance = this;
- }
- // Use this for initialization
- void Start () {
- //找到预设物
- stone = Resources.Load<GameObject>("Prefabs/Stone");
- prop = Resources.Load<GameObject>("Prefabs/Prop");
- //InvokeRepeating("createStone",1f,1f);
- }
-
- // Update is called once per frame
- void Update () {
-
- }
- //生成石头 x轴生成位置在一定范围内随机 y z坐标固定
- public void createStone()
- {
- GameObject go = Instantiate(stone);
- go.transform.position = new Vector3(Random.Range(-3.37f, 3.64f), Random.Range(0.595f,2.595f), -11.34f);
- }
- //生成道具 随机生成1-100的数字 如果num大于等于80 道具生成 位置跟石头位置一样
- public void createProp()
- {
- int num = Random.Range(1,100);
-
- if (num>=80)
- {
- GameObject go = Instantiate(prop);
-
- go.transform.position = new Vector3(Random.Range(-3.37f, 3.64f), Random.Range(0.595f, 2.595f), -11.34f);
- }
- }
- //停止石头和道具的生成 游戏结束时调用
- public void stopStone()
- {
- CancelInvoke("createStone");
- }
- public void stopProp()
- {
- CancelInvoke("createProp");
- }
- }
|