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 PathManager : MonoBehaviour
- {
- public static float RY = 0;
- public List<Path> paths;
- public int maxPaths = 40;
- public GameObject pathPrefab;
- public GameObject pathPrefab2;
- public GameObject pathPrefab3;
- public Vector3 nextPosition;
- public int sameTurnsL = 0;
- public int sameTurnsR = 0;
- public bool lastStraight = false;
- // Start is called before the first frame update
- void Start()
- {
- for (int i = 0; i < maxPaths; i ++)
- {
- if (RY == -360f)
- {
- RY = 0f;
- }
- var chooseFloat = Random.Range(0f,1f);//testing
- //GameObject go = null;
- if (chooseFloat <= 0.3 || i == 0)
- {
- GameObject go = Instantiate<GameObject>(pathPrefab);
- Path path = go.GetComponent<Path>();
- if (i == 0)
- {
- nextPosition = path.attachPoint.transform.position;
- }
- else
- {
- //var nextTransform = path.attachPoint;
- go.transform.position = nextPosition;// - path.startPoint.transform.position;
- go.transform.rotation = Quaternion.Euler(0, RY, 0);
- nextPosition = path.attachPoint.transform.position;
- }
- lastStraight = true;
- }
- else if (chooseFloat > 0.3 && chooseFloat <= 0.7)
- {
- if (sameTurnsL < 2)
- {
- GameObject go = Instantiate<GameObject>(pathPrefab2);
- Path path = go.GetComponent<Path>();
- if (i == 0)
- {
- nextPosition = path.attachPoint.transform.position;
- RY -= 90;
- }
- else
- {
- //var nextTransform = path.attachPoint;
- //fix all the offsets------------
- if (RY == 0)
- nextPosition.z -= 0.5f;
- else if (RY == 90 || RY == -270)
- nextPosition.x -= .5f;
- else if (RY == 180 || RY == -180)
- nextPosition.z += 0.5f;
- else if (RY == -90)
- nextPosition.x += .5f;
- //that was annoying :)-------------
- go.transform.position = nextPosition;// - path.startPoint.transform.position;
- go.transform.rotation = Quaternion.Euler(0, RY, 0);
- RY -= 90;
- nextPosition = path.attachPoint.transform.position;
- }
- sameTurnsL += 1;
- lastStraight = false;
- if (sameTurnsR > 0)
- {
- sameTurnsR -= 1;
- }
- }
- else
- {
- GameObject go = Instantiate<GameObject>(pathPrefab);
- Path path = go.GetComponent<Path>();
- if (i == 0)
- {
- nextPosition = path.attachPoint.transform.position;
- }
- else
- {
- //var nextTransform = path.attachPoint;
- go.transform.position = nextPosition;// - path.startPoint.transform.position;
- go.transform.rotation = Quaternion.Euler(0, RY, 0);
- nextPosition = path.attachPoint.transform.position;
- }
- lastStraight = true;
- sameTurnsL -= 1;
- }
- }
- else
- {
- if (sameTurnsR < 2)
- {
- GameObject go = Instantiate<GameObject>(pathPrefab3);
- Path path = go.GetComponent<Path>();
- if (i == 0)
- {
- nextPosition = path.attachPoint.transform.position;
- RY += 90;
- }
- else
- {
- //var nextTransform = path.attachPoint;
- //fix all the offsets------------
- if ((RY) == 0)
- nextPosition.z += .5f;
- else if ((RY) == 90 || RY == -270)
- nextPosition.x += .5f;
- else if ((RY) == 180 || RY == -180)
- nextPosition.z -= .5f;
- else if (RY == -90)
- nextPosition.x -= .5f;
- //that sucked :)----------------
- go.transform.position = nextPosition;// - path.startPoint.transform.position;
- go.transform.rotation = Quaternion.Euler(0, RY, 0);
- RY += 90;
- nextPosition = path.attachPoint.transform.position;
- }
- sameTurnsR += 1;
- if (sameTurnsL > 0)
- {
- sameTurnsL -= 1;
- }
- lastStraight = false;
- }
- else
- {
- GameObject go = Instantiate<GameObject>(pathPrefab);
- Path path = go.GetComponent<Path>();
- if (i == 0)
- {
- nextPosition = path.attachPoint.transform.position;
- }
- else
- {
- //var nextTransform = path.attachPoint;
- go.transform.position = nextPosition;// - path.startPoint.transform.position;
- go.transform.rotation = Quaternion.Euler(0, RY, 0);
- nextPosition = path.attachPoint.transform.position;
- }
- lastStraight = true;
- sameTurnsR -= 1;
- }
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement