So I've been working on a little project that involves Valve's "Portal" style portals, the type where you can seamlessly see what's on the other side and walk through. I've run into a problem when it comes to teleporting an object to it's new location upon hitting the portal. I have a List<GameObject>
that contains all the objects that are in close enough range to feasibly travel through the portal, but when I try to modify the transform.position
of one of these GameObjects, nothing happens, no error messages.
So I've been going through my script line by line and writing little dummy functions to test different parts of it to see where the problem lies, and everything seems to work up until I index the list and try to modify a value, nothing happens. So was thinking that perhaps the List doesn't actually contain a reference to the GameObject in the scene, but simply a copy of the GameObject's data at the time it was passed into the list. So I checked this by making the list public so that I see it in the inspector, and when I click on an item in the list it highlights that same GameObject in the hierarchy, which suggests it is actually a reference. See bellow...
I am at a loss as to what's happening here and would really appreciate if anyone could offer a suggestion, Here is the dummy function where I try to arbitrarily modify the GameObject data from the List...
if (Input.GetKeyDown("k"))
{
for (int i = 0; i < trackedTravelersObjects.Count; i++)
{
trackedTravelersObjects[i].transform.position += new Vector3(0, 30, 0);
Debug.Log("K");
}
}
You'll notice a Debug.Log("k")
, this is just to check that the code is actually being called, which it is.
Thanks.
CharacterController.Move()
method to move around based on keyboard input. \$\endgroup\$