Call Other Object to Self

Hey Everybody So I am working on an FPS Shooter with unlockable weapons and what happens is when I unlock a weapon, it randomly places it on the level somewhere. Is there a script that I could attach to the Player to call the weapon to its position and rotation at the start of the level? Thanks!!!

(Also is there a way to add variables to that so I can make it a relative position to the player at the beginning of the level… Does that make Sense?)
Thanks in advance again!!

CLARIFICATION:
Well to clarify, what happens is I have an unlocked weapon already that stays on each level DontDestroyOnLoad. I have a player named ASHOOTER (which is my player) What i wanted was a script that is a component of ASHOOTER that “calls” the weapon to its current position and rotation. In the same script, I wanted variables where in the inspector I could make it called to a position relative to the ASHOOTER.
So for example if ASHOOTER is at (1, 1, 1). And in the inspector the relative values for x, y, and z were all -.5, then the weapon would get called to (.5, .5, .5)

I’m not sure what you mean in your first question about making a script to attach to the player. The design is up to you. Maybe clarify that a bit.

For your second question what I think you are asking is can you have the unlocked weapon spawn in a random place relative to the current player position. If this is the case you could do this a number of ways.

  1. You could use the transform to get a random position with a max X distance from the player of maxX and max Z position maxZ (assuming you use X and Z coords for the 2d plane of the ground)

    Vector3 randSpawnPos = new Vector3(playerTransform.x + Random.Range(-maxX, maxX), playerTransform.y /(or whatever height you want)/, playerTransform.z + Random.Range(-maxZ, maxZ));

  2. You could use a Random.insideUnitCircle to get a random position in a circle around your player then use a random value for the distance from your player

    float radius = Random.Range(minRadius, maxRadius);
    Vector2 randPos = Random.insideUnitCircle * radius;

You could set the radius to a constant or randomly get one like coded above.

Hopefully this is helpful.

Edit: Sorry, I misunderstood your question.

you could attach this to your weapon:

    var player : GameObject;
    var xOffset : float = .5;
    var yOffset : float = .5;
    var zOffset : float = .5;
    var xRotationOffset : float = 0.0;
    var yRotationOffset : float = 0.0;
    var zRotationOffset : float = 0.0;
    
    function Start(){
    player = GameObject.Find("ASHOOTER");
    transform.position = Vector3(player.transform.position.x + xOffset,player.transform.position.y + yOffset,player.transform.position.z + zOffset);
    transform.rotation = player.transform.rotation;
    transform.Rotate(Vector3(xRotationOffset,yRotationOffset,zRotationOffset));
    transform.parent = player.transform; // this childs the weapon to the player so it will stay with him...
    }

it’s basic, but this should work I think…
all the offsets will be visible in the inspector…

to fine tune the positions, you can change it from start to update, then change it back to start to save on performance (once you know what values to use)…

EDIT: tried to add rotation vars, I THINK that should work