Defining a local spawn offset

var x = transform.position.x + Random.Range(-10,10);
var z = transform.position.z + Random.Range(-10,10);
var posn = Vector3(x,transform.position.y,z);

How can I write this so that “posn” refers to the local x/z axis of the gameobject which is running the script, as opposed to x/z relative to world space?

I am basically trying to instantiate a series of objects at “posn” which should be a random X and Z offset relative to the game object rather than the world.

I’ve tried using TransformDirection but I don’t seem to be able to incorporate it into this script without a load of errors, perhaps as I am already using a vector3 to define posn?

Not sure if I fallow correctly but if you wanted a vector local to the gameObject.transform it would be

posn = posn - transform; which in your code above would be the same as

post = new Vector3(Random.Range(-10,10), 0, Random.Range(-10,10));