Hi guys, i got a problem and i hope you guys will help me with a solution. i creating a game like doodle jump, so i am spawning a enemy, the enemy spawn just in a random place in air. i want i to spawn on a platform.
i want finalpostion to be equal to nearest platform position, every time the enemy spawns. heres the code:
using UnityEngine;
using System.Collections;public class EnemySpawner : MonoBehaviour {
public GameObject[] Enemy; public float MinTime = 2f; public float MaxTime = 20f; public bool spawning = false; public SpawnerScript1 pos; void Update() { if (!spawning) { StartCoroutine(SpawnEnemy()); } } IEnumerator SpawnEnemy() { spawning = true; //Wait for random time before respawning yield return new WaitForSeconds(Random.Range(MinTime, MaxTime)); //Set random position inside X&Y axis and materialize Vector2 finalposition = new Vector2(pos.position.x, pos.position.y - 1.2f); Instantiate(Enemy[Random.Range(0, Enemy.Length)], finalposition, Quaternion.identity); spawning = false; }
}
``