How do i get an object to be in between two other objects that I specify

hello, i am wanting to know how to have a script that make the object this script is attached to move to a position that is exactly in between two specified objects ans stay in between them all the time

This is called the midpoint formula.

edit: assuming you want your object to be placed in the middle of two others:

public GameObject object1;
public GameObject object2;

void Awake()
    this.transform.position = 0.5f*(object1.transform.position + object2.transform.position);

okay, that is great but you see i want a script that makes the object the script is attached to be in the middle of the two objects, the

middleObject.transform.position = (object1.transform.position + object2.transform.position) *0.5;

code you gave me is good but the middleObject seems to be a variable name that i have to put in but i want it to say that itself will be in the centre of the two objects

the new script you posted doesn’t work, but i was able to edit the first code you gave me with a little from the new one, i am also wanting to know how to have the scale of the z axis of the object as the distance of the two objects minus 1, if any of you could help me with it, i would be very thankful