private void GenerateBlock() { if (Random.Range(0, 100) < randomBlockSpawnPercent) { GenerateRandomBlock(); return; } int r = Random.Range(0, blocks.Count); GameObject g = Instantiate(blocks[r], Vector3.zero, transform.rotation, transform); BlocksSegment b = g.GetComponent <BlocksSegment>(); g.transform.localPosition = new Vector3(0, PlayerHeight - 0.35f, spawningDistance); b.Velocity = new Vector3(0, 0, -currentSpeed); var length = Mathf.Approximately(b.length, 0f) ? b.getLength() : b.length; timer = (length + distanceBetweenSegments) / currentSpeed; if (spawnWatermelons) { toNextWall--; } if (toNextWall <= 0) { timer += 0.2f; } }
public BlocksSegment SpawnSegment() { var r = Random.Range(0, segments.Length); BlocksSegment segmentInstance = Object.Instantiate(segments[r], Vector3.zero, Parent.rotation, Parent); segmentInstance.transform.localPosition = new Vector3(0, PlayerHeight - 0.2f, spawningDistance); segmentInstance.Velocity = new Vector3(0, 0, -currentSpeed); return(segmentInstance); }