Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameObject mountains;
- public float mountainSpawnRateMax;
- public float mountainSpawnRateMin;
- public float maxZ;
- public float minZ;
- public float maxScalex;
- public float minScalex;
- public float maxScaley;
- public float minScaley;
- public float mountainSpeed;
- bool t;
- void OnEnable()
- {
- Rigidbody2D[] m = GetComponentsInChildren<Rigidbody2D>();
- foreach (Rigidbody2D mnt in m)
- {
- mnt.velocity = new Vector3(-1 * mountainSpeed, 0, 0);
- }
- t = true;
- Invoke("SpawnMountain", Random.Range(mountainSpawnRateMin, mountainSpawnRateMax));
- }
- void OnDisable()
- {
- t = false;
- }
- void SpawnMountain()
- {
- float ranZ = Random.Range(minZ, maxZ);
- Vector3 spawnPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + ranZ);
- GameObject mountain = Instantiate(mountains, spawnPos, Quaternion.identity) as GameObject;
- mountain.GetComponent<Rigidbody2D>().velocity = new Vector3(-1 * mountainSpeed, 0, 0);
- mountain.transform.parent = transform;
- float ranScalex = Random.Range(minScalex, maxScalex);
- float ranScaley = Random.Range(minScaley, maxScaley);
- mountain.transform.localScale -= new Vector3(ranScalex, ranScaley, 0);
- if(t == true)
- {
- Invoke("SpawnMountain", Random.Range(mountainSpawnRateMin, mountainSpawnRateMax));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement