I’m making a game for my class, around the concept of “using the first person camera in a unique way”. I came up with a concept of a maze game where certain walls (3 walls meeting at a dead end and an invisible cube with a trigger at the dead end), when you are inside them, and press “E”, are childed to the player, and then rotate with Mouse Look.
This works, but for only one object.
I was referring to the “TriggerRotator” object (what I called it), by “finding” it by name, and childing it to the player in the player’s script, but that only works for one object. Now, I’m calling a seperate script on the “TriggerRotator”, and childing it to the player there
The “TriggerRotator” object is a prefab, and I drag more out into my scene, and if I test them, only the original one I made before prefabbing it works.
public void childToPlayer()
{
Debug.Log ("Other Script is Being Called");
this.transform.parent = player.transform;
}
I would have thought that the use of “this” on the rotator object would child all instances of the rotator object to the player, which is what I want. But it still only works on one. Is there a way to affect all instances of “this”?
Simply put (and only thing I know about keyword) “this” only refers to class itself / transform / Gameobject that particular instance of script is attached to.
For example, this.transform means transform of whatever game object this instance of script is attached to.
Other than that your approach should work, each colliding objects should get the event → your character walks into x amount of triggers (all at same location), presses button, scripts of each trigger object should be executed…
Are you sure that you player has Rigidbody and each of objects you want to attach/has script do really have collider?
After rubber duck programming with my peers, we realized that “Rotator”, which was “finding” an object tagged RotatorTrigger was only finding ONE instance. I put all RotatorTriggers inside an empty game object and it worked.
Well, all objects can rotate, but rotate around the player, but that’s a different problem, and one I can figure out.