My game is 2D. I have my game currently set up with several different spawners. I have a left side spawner, right side spawner, and bottom spawner. There are 3 different spawn points in each spawner for a total of 9 spawn points. While this is working it is not what I want exactly. I wanted to have all of my spawn points in 1 array and spawn an enemy in a randomly chosen position from the 9 spawn points. I am unable to do this because my sprites are facing right. I need to flip the sprite depending on which spawn point is selected. If it is on the right side (if(spawnpoint[spawnindex].position.x>0)) flip the sprite. I have tried many things, but nothing seems to work. I would also need to rotate a 2D sprite 90 degrees when it is instantiated at one of the bottom spawn points. I think it may have something to do with where I am calling the arguments, but I have also messed around with that and have had no luck. I would really appreciate some help or guidance.
Here is my code (with several unsuccessful attempts):
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TempSpawner : MonoBehaviour{
//public float runningPlayerSpeed;
public Transform []spawnPoints;
public float spawnTime = 2f;
public GameObject [] Players;
//public SpriteRenderer mySpriteRenderer;
//public float minSpeed;
//public float maxSpeed;
//private float currentSpeed;
void Start(){
InvokeRepeating ("SpawnPlayers", spawnTime, spawnTime);
//currentSpeed = Random.Range (minSpeed, maxSpeed);
}
void Update(){
//float amountToMove = currentSpeed * Time.deltaTime;
//transform.Translate (Vector3.right * amountToMove);
//int spawnIndex = Random.Range (0, spawnPoints.Length);
//int objectIndex = Random.Range (0, Players.Length);
//foreach (var player in Players) {
/*if (spawnPoints [spawnIndex].position .x > 0) {
tempPos = transform.position;
tempPos.x = -0.05f;
transform.position = tempPos;
}
if (spawnPoints [spawnIndex].position .x < 0) {
tempPos = transform.position;
tempPos.x = 0.05f;
transform.position = tempPos;
}*/
//player.GetComponent <SpriteRenderer > ().flipX = spawnPoints [spawnIndex].position.x > 0;
/*if (spawnPoints [spawnIndex].position.x < 0) {
player.GetComponent <SpriteRenderer > ().flipX = true;
}
if (spawnPoints [spawnIndex].position.x > 0) {
player.GetComponent <SpriteRenderer > ().flipX = false;
}*/
}
/*if (spawnPoints [spawnIndex].position.x == 10) {
player.GetComponent <SpriteRenderer > ().flipX = true;
//SpriteRenderer sr = gameObject.GetComponent<SpriteRenderer>();
//sr.flipX = true;
//Players [objectIndex].GetComponent <SpriteRenderer > (mySpriteRenderer );
//mySpriteRenderer.flipX = true;
//Players [objectIndex].transform.localScale.x == -1f;
//mySpriteRenderer.flipX = true;
//GameObject.FindGameObjectsWithTag ("Running Players");
} else if (spawnPoints [spawnIndex].position.x == -10) {
player.GetComponent <SpriteRenderer > ().flipX = false;
}
}*/
void SpawnPlayers(){
int spawnIndex = Random.Range (0, spawnPoints.Length);
int objectIndex = Random.Range (0, Players.Length);
Instantiate (Players [objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation );
}
}