we don't fully know how Unicron plays into it, but the story itself, Megatron (beast wars, the one thats a dinosaur) dies and goes to the afterlife, which apparently perfectly resembles the tree of life. He is guided to ascend different branches and spheres of it which are supposed to teach him different things to prepare him for the final aspect of it, where he merges back with the "Allspark" (which is just Primus or part of him, this isn't explicitly stated but we know it from other lore). Because Megatron has a god-sized ego, he decides in the end he would rather kill himself and the angel trying to guide him than lose his individuality and become one with God.
Relevant to Unicron, Primus was made out of half of Unicron, so presumably he embodies something equally strange.