how to make “cube1” turn into “cube2” with the same position and rotation when touching the trigger
Depends on what you are trying to do. If you really want to replace one game object with another, remember that you will lose any state values associated with the first. So, if you’re storing health, strength etc on the first prefab, when you use the second, it will lose all those values. If that’s really what you want, the method is:
Instantiate both in the game to start with.
Make the second inactive – use SetActive(false)
OnTriggerEnter: make the fist inactive and the second active
use the transform.setPositionAndRotation method to copy first to second.
If all GameObject Attributes are held elsewhere (eg in a health manager, skills manager etc) then this can still work.
However, what you may want is not to change prefab but to change the skin. Search for Change Skin on YouTube. Plenty of tutorials to help with that…