gimm-platformer-project/Assets/Scripts/PlatformManager.cs
2022-10-07 13:18:54 -06:00

26 lines
893 B
C#

using UnityEngine;
public class PlatformManager : MonoBehaviour
{
// Array setup for platforms
GameObject[] platforms;
GameObject currentPlatform;
int index;
// GameObject for coin appearing above platform
public GameObject coin;
private void Start()
{
NewPlatform();
}
// Start is called before the first frame update
public void NewPlatform()
{
platforms = GameObject.FindGameObjectsWithTag("Platform"); // Creates an array of all objects with the tag platform
index = Random.Range(0, platforms.Length); // randomly selects one platform
currentPlatform = platforms[index]; // registers random platform as the one the player must get to
var position = currentPlatform.transform.position;
coin.transform.position = new Vector2(position.x, position.y + 2f);
}
}