private void Initialize(PlatformScript parent, Vector3 pos, string n) { willFall = true; gm = FindObjectOfType <RestrictionScript> (); obs = GameObject.FindGameObjectWithTag("Respawn"); mesh = parent.mesh; material = parent.material; transform.parent = parent.transform; transform.localScale = Vector3.one; endPos = pos; //pos.y = -2f; startPos = pos; startTime = Time.deltaTime; isMoving = true; transform.localPosition = pos; posName = n; int x = 0; PlatformScript[] ps = FindObjectsOfType <PlatformScript> (); foreach (PlatformScript p in ps) { if (transform.position == p.transform.position) { x++; if (x == 2) { Destroy(gameObject); //Destroy duplicates } } } if (gm.rNum >= 4) { float distance = Random.Range(0.05f, 0.165f); if (transform.position.x > 0) { pos.x += distance; } else { pos.x -= distance; } transform.localPosition = pos; //Platform distance } if (gm.rNum >= 3) { float xpos = Random.Range(-0.425f, 0.425f); float ypos = Random.Range(0.3f, 1.5f); pos = new Vector3(xpos, ypos, 0); GameObject ob = Instantiate(obs, Vector3.zero, Quaternion.identity, gameObject.transform); //Spawn obstacle ob.transform.localPosition = pos; Color c = new Color(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f)); ob.GetComponent <MeshRenderer> ().material.color = c; } if (x < 2) { float r1 = Random.Range(0, 10); float r2 = Random.Range(0, 10); float r3 = Random.Range(0, 10); if (r1 <= 5) { gm.SpawnStuff(1, transform.position); } if (r2 <= 7) { gm.SpawnStuff(2, transform.position); } if (r3 <= 4) { gm.SpawnStuff(3, transform.position); //Spawn stuff } } }
private void Initialize(TerrainScript parent, Vector3 pos, string n) { willFall = true; pos.x += 10; gm = FindObjectOfType <RestrictionScript> (); obs = GameObject.FindGameObjectWithTag("Respawn"); terrain = parent.terrain; transform.parent = parent.transform; transform.localScale = Vector3.one; transform.localPosition = pos; posName = n; int x = 0; TerrainScript[] ps = FindObjectsOfType <TerrainScript> (); foreach (TerrainScript p in ps) { if (transform.position == p.transform.position) { x++; if (x == 2) { Destroy(gameObject); //Destroy duplicates } } } if (gm.rNum >= 4) { float distance = Random.Range(0.05f, 0.165f); if (transform.position.x > 0) { pos.x += distance; } else { pos.x -= distance; } transform.localPosition = pos; //Platform distance } if (gm.rNum >= 3) { float xpos = Random.Range(-0.425f, 0.425f); float ypos = Random.Range(0.3f, 1.5f); pos = new Vector3(xpos, ypos, 0); GameObject ob = Instantiate(obs, Vector3.zero, Quaternion.identity, gameObject.transform); //Spawn obstacle ob.transform.localPosition = pos; } if (x < 2) { float r1 = Random.Range(0, 10); float r2 = Random.Range(0, 10); float r3 = Random.Range(0, 10); if (r1 <= 4) { gm.SpawnStuff(1, transform.position); } if (r2 <= 6) { gm.SpawnStuff(2, transform.position); } if (r3 <= 4) { gm.SpawnStuff(3, transform.position); //Spawn stuff } } }