how to add slight randomness to instantiated objects

im working in c#. i googled and found some code that said “blahobject.transform.position[random.range(0,10)]” for the position of the instantiated object, but it doesn’t work. I’m actually using a ray hit point as the position to instantiate so my code looks like this:

GameObject bullet = Instantiate(bulletShell, hit.transform.position, hit.transform.rotation) as GameObject;

I just want to add some slight randomness so that the bullets don’t instantiate in the exact same spot.

First note that ‘hit.transform.position’ is the position of the object hit. The position of the hit itself is hit.point. You can generate a random delta from the position like this:

Vector3 pos = hit.transform.position + Random.insideUnitSphere * radius.  

…where ‘radius’ is the maximum you want to allow the position to deviate from the base position. You would then use ‘pos’ as the position in your Instantiate(). Note if you are doing this to avoid instantiate objects from colliding with each other, pick another solution. This randomness does not prevent Instantiated objects from hitting each other.