Question by
austinF144 · Aug 11, 2017 at 06:49 AM ·
gameobjectarraytagrandom.rangeselection
How to change a game objects tag after it has been randomly selected?
I'm working on a game that has multiple killers (with different traits) in it. However only one is selected at the beginning of the game, that way the game is different every time. Right now I have an array that randomly selects a killer and the debug.log tells me who has been selected and that part works. I am trying to then use that change the tag from "civilian" to "killer".
using UnityEngine; using System.Collections;
public class whoIsKiller : MonoBehaviour {
public Transform[] Killers;
public float InvokeRate = 1.0f;
void Start()
{
InvokeRepeating ("pickKiller", 1.0f, InvokeRate);
}
void pickKiller()
{
int indexNumber = Random.Range(0, Killers.Length);
Debug.Log(Killers[indexNumber].name);
// this is not changing the tag on the selected killer.
gameObject.tag = "killer";
}
}
I can't imagine that invokeRepeating is the best way to do this however I have it set to 0 in engine and it only selects once at the beginning.
Comment