I am making a 2D game where you have to drop down platforms and avoid being brought up to a certain point. Unfortunately, I cannot game the platforms to move up. I have tried both with Vector3.MoveTowards and rb.velocity, the latter of which I did not choose because I need the platforms to be static. With the MoveTowards method, it still doesn’t work. Here are the scripts:
//START SPAWNING PLATFORMS
void Start()
{
StartCoroutine(InstantiatePlatforms());
}
void Update()
{
//PLATFORM MOVEMENT
platform.GoUp(upSpeed);
}
// SPAWN PLATFORMS
public IEnumerator InstantiatePlatforms()
{
GameObject spawnedObject = platforms[Random.Range(0, platforms.Length)];
Vector3 spawnPosition = new Vector3(Random.Range(-1, 3), -10, 0);
Instantiate(spawnedObject, spawnPosition, Quaternion.identity);
yield return new WaitForSeconds(1);
StartCoroutine(InstantiatePlatforms());
}
void IncreaseDifficulty()
{
upSpeed++;
}
and the script for the platforms:
public void GoUp(float upSpeed)
{
transform.position = Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, 8, transform.position.z), Time.deltaTime * upSpeed);
}
I have never worked with 2D and am wondering where I messed up. Thank you in advance!
BTW I set upSpeed to 10 and assigned every public variable.