I’ve searched through the various scripting references, but haven’t managed to recognize how to do what I want:
I’m trying to make objects loop across my 2D map until they’re destroyed by the player.
I have a Boundary with a box collider. When an object exits -
void OnTriggerExit (Collider other)
- I want to grab other’s Transform position, and if x or z is greater than 20 or less than -20 I want to multiply that value by -1, teleporting it to the other side of the map. My assumption is that since it’s not changing velocity but exclusively position, the object will then keep rolling along, back onto the map for another crossing.
Right now it’s giving me an error type CS1612: Cannot modify a value type return value of ‘UnityEngine.Transform.position’. Consider storing the value in a temporary variable.
Apparently I’m unclear how to either initialize or correctly attach a temporary Vector3 for this purpose, because the system has rejected my attempts as invalid.