After picking a random object from an array, how to run the functions only for the chosen object?
So I'm having a GameOject array calls swords. The game objects I'm going to put in the array are 12 same objects with a scripts on them that included all the functions once start. Then I try to pick a random object out of 12 every 1 second and call that object chosenSword.
Right now I want to add functions for the random object just got chosen. So every time it choose an object, the functions will only start for that specific object. Those who hasn't get choose will not going to do anything until the PickingRandom() choose it.
I don't know how to make Unity understand only do the functions when a game object has been chosen.
public class SwordManager : MonoBehaviour { public GameObject[] swords;
public GameObject chosenSword;
int index;
// Use this for initialization
public void Start () {
InvokeRepeating("PickingRandom", 2.0f, 1f);
}
// Update is called once per frame
void Update () {
}
public void PickingRandom () { swords = GameObject.FindGameObjectsWithTag("Sword"); index = Random.Range(0, swords.Length); chosenSword = swords[index]; } }