Enemy Selection Screen

Hi all,

I would like to create an enemy selection screen where a user can pick between the character that they want to fight. I have two questions. Image upload isn’t working for some reason so I’ll describe it as best I can. So if I have button A (character 1) and button B (character 2) if user selects B, how can I make ‘A’ become slightly transparent while making B opaque & vice versa? (to make it clear which opponent is selected)

The second is, how do I take selection A or B and have the spawner use that information? Right now it just spawns all sprites in the pool, how do I tell it to only spawn a certain sprite instead?

Here’s the spawn script if it helps:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Spawner : MonoBehaviour {
   
    private GameObject[] gameObjPool;
    private Queue<GameObject> availableGOQueue = new Queue<GameObject>();
    private Camera cam;
   
    // These are used to determin spawning frequency
    public float minSpawnTime = 0.05f;
    public float maxSpawnTime = 0.50f;
   
    // Spawning offset (relative to the Spawner object)
    public float spawningOffsetTop = 0f;
    public float spawningOffsetBottom = 0f;
   
    void Start(){
        gameObjPool = new GameObject[transform.childCount];
        cam = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();
        int i = 0;
        foreach(Transform childTr in this.transform){
            // Populate gameObjPool by fetching the children list of the spawner
            gameObjPool[i] = childTr.gameObject;
            // Set object position = to parent's position and make it invisible
            resetObject(gameObjPool[i]);
            i++;
        }
        // Then call the spawning method
        Invoke("spawnObject", Random.Range(minSpawnTime, maxSpawnTime));
    }
   
    // This actualy does the job...
    void spawnObject(){
        // First check for objects out of view
        for(int i=0; i < gameObjPool.Length; i++){
            // Convert object position to screen point, so that we can test object position relatively to camera viewport
            Vector3 screenPt = cam.WorldToScreenPoint(gameObjPool[i].transform.position);
            // Left border
            if(gameObjPool[i].activeSelf == true && screenPt.x < 0){
                resetObject(gameObjPool[i]);
            }
        }
       
        // Spawn an object only if available
        if(availableGOQueue.Count > 0){
            GameObject gameObj = availableGOQueue.Dequeue();
            // Set random offset...
            gameObj.transform.Translate(Vector2.up * Random.Range(spawningOffsetTop, spawningOffsetBottom));
            // Activate the object
            gameObj.SetActive(true);
        }
        // Recursively call this method randomly
        Invoke("spawnObject", Random.Range(minSpawnTime, maxSpawnTime));
    }
   
    public void resetObject(GameObject obj){
        // Deactivate object, reset its position and enqueue it for another spawn
        obj.SetActive(false);
        obj.transform.position = this.transform.position;
        availableGOQueue.Enqueue(obj);
    }
   
}

Any help would be appreciated.

Thanks!

Could you assign each character a value using an int then that relates to their location in the character list/array & instantiate that object?

Hi Ted,

Thanks for the response. Possibly - could you explain a little further? I’m still quite new to Unity.

add the Selectable component to an image to make it selectable