gimm-platformer-project/Assets/Scripts/PlatformManager.cs

27 lines
893 B
C#
Raw Normal View History

2021-10-31 13:43:04 -06:00
using UnityEngine;
2021-09-24 00:34:18 -06:00
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
2022-10-07 13:18:54 -06:00
var position = currentPlatform.transform.position;
coin.transform.position = new Vector2(position.x, position.y + 2f);
2021-09-24 00:34:18 -06:00
}
}