Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GameController : MonoBehaviour
- {
- [SerializeField]
- private int SpawnCount = 35;
- [SerializeField]
- private GameObject cactus;
- [SerializeField]
- private GameObject[] SpawneObjects;
- void Awake() {
- SpawneObjects = new GameObject[SpawnCount];
- cactus = Resources.Load("Cactus_01") as GameObject;
- }
- void Start() {
- for (int i = 0; i < SpawnCount; i++) {
- SpawneObjects[i] = cactus;
- SpawneObjects[i].transform.position = transform.position;
- }
- Vector3 NewPos = Vector3.zero;
- int a = 0;
- for (int i = 0; i < SpawnCount-1; i++) {
- N: NewPos.x = Random.Range(16.0f, 85.0f);
- NewPos.y = 0.1f;
- NewPos.z = Random.Range(17.0f, 86.0f);
- a = i;
- if(i == 0){
- SpawneObjects[i] = SpawnStaticObject(NewPos);
- continue;
- }
- if ( (Mathf.Abs(NewPos.x) - 10 > Mathf.Abs(SpawneObjects[i-1].transform.position.x) &&
- Mathf.Abs(NewPos.z) - 10 > Mathf.Abs(SpawneObjects[i - 1].transform.position.z)) ||
- //(Mathf.Abs(NewPos.x) - 7 > Mathf.Abs(SpawneObjects[i].transform.position.x) &&
- // Mathf.Abs(NewPos.z) - 7 > Mathf.Abs(SpawneObjects[i].transform.position.z)) ||
- (Mathf.Abs(NewPos.x) - 10 > Mathf.Abs(SpawneObjects[i+1].transform.position.x) &&
- Mathf.Abs(NewPos.z) - 10 > Mathf.Abs(SpawneObjects[i+1].transform.position.z))) {
- Debug.Log(i);
- SpawneObjects[i] = SpawnStaticObject(NewPos);
- continue;
- } else {
- i = a;
- goto N;
- }
- }
- }
- private GameObject SpawnStaticObject(Vector3 pos) {
- return Instantiate(cactus, pos, Quaternion.identity) as GameObject;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement