Spawn script !! Y axis not working
Can someone help me with my spawn script. I have a spawn script attach to a cube placed in my game that spawn prefabs on that cube (stretched out) but on the X axis, when I try to place the same script on a cube on the Y axis , the prefabs just spawn at the same place and not randomly on the cube. Could somebody help me , so that the cube on the Y axis spawns randomly on the cube (stretch out) and not at the same place. Thank you
Sorry I forgot, here's my code:
pragma strict
// Variable to store the enemy prefab public var enemy : GameObject; // Variable to know how fast we should create new enemies public var spawnTime : float = 2; function Start() {
// Call the 'addEnemy' function every 'spawnTime' seconds InvokeRepeating("addEnemy", spawnTime, spawnTime); } // New function to spawn an enemy function addEnemy() {
// Variables to store the X position of the spawn object // See image below var x1 = transform.position.x - GetComponent.().bounds.size.x/2; var x2 = transform.position.x + GetComponent.().bounds.size.x/2; // Randomly pick a point within the spawn object var spawnPoint = new Vector2(Random.Range(x1, x2), transform.position.y); // Create an enemy at the 'spawnPoint' position Instantiate(enemy, spawnPoint, Quaternion.identity);