Random Y Position

I was wondering how I can implement a Random.Range on the y position to make it so it gets a random position on the offset. Here’s the script I’m using.

using UnityEngine;

public class CloudFollow : MonoBehaviour
{

public Transform player;
public Vector3 offset;

void Start()
{

    

}

// Update is called once per frame
void Update()
{
    Vector3 position = transform.position;
    position.y = (player.position + offset).y;
    transform.position = position;
}

}

Hi there!

Well, I don’t know exactly the kind of behavior you are looking for, but if you follow this kind of thing in your Start function probably, you can give offset’s y value a random number before it starts moving:

Vector3 offset = Vector3.zero;
float randomY = Random.Range(-10.0f, 10.0f); // Min = -10.0f, Max = 10.0f
offset += new Vector3(0, randomY, 0);

Hi so I added that script to my start function and my clouds (the thing I want to spawn on random Y positions) aren’t really changing their y position. Not really sure what is going on but I’d really appreciate some more help. @Stratosome

    void Start()
    {
        Vector3 offset = Vector3.zero;
        float randomY = Random.Range(-10.0f, 10.0f); // Min = -10.0f, Max = 10.0f
        offset += new Vector3(0, randomY, 0);
    }


    // Update is called once per frame
    void Update()
    {
        Vector3 position = transform.position;
        position.y = (player.position + offset).y;
        transform.position = position;
    }
}