I am trying to create a game, or simulation rather where you walk around the room and collect cubes. When you “collect” one by walking into it, it will up your score by one and move the pickup to a different location within the room. In order to keep the cube in the room, I randomized the new transform by creating a series of reference points nearby and setting the transform equal to one of those.
// Use this for initialization
void Start ()
{
References.Add(Reference);
References.Add(Reference1);
References.Add(Reference2);
References.Add(Reference3);
References.Add(Reference4);
References.Add(Reference5);
References.Add(Reference6);
References.Add(Reference7);
References.Add(Reference8);
References.Add(Reference9);
References.Add(Reference10);
References.Add(Reference11);
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("PickUp"))
{
other.gameObject.transform.position = References[Random.Range(0, References.Count)].transform.position;
}
}
}
You’ll see, I created a list, added my twelve reference gameObjects to the list, then when you collide with the pickup, it is supposed to transport to another one of them at random but it doesn’t. The player just clips through the pickup. Any help with this is appreciated, and I am relatively new with unity so apologies for any mistakes in code formatting, or inefficiencies.