so how can I place the randomly generated obstacles and coins along the up and down hill of the ground am driving on thank you

Hey thank for your time am kind of new for unity but am touting my self unity2d so…here is the question I want to make a 2d endless car game like hill climb and so I have done with endless scrolling back ground and a car model but I want to create an randomly generated obstacle and coins with prefab but the ground has up hills and downhill so how can I place the randomly generated obstacles and coins along the up and down hill of the ground am driving on thank you. Can’t find any tutorials on endless 2d car games if you have recommendations and solution I’ll be happy

ya your right @ tormentoarmagedoom i was trying to ask like that"How i detect the surface of a random generated ground" am kinda new for game development that is why i miss the technical words anyways thanks

@yyddaa This is something I just tested and it should work for you. Attach this script to an object and place the object above the hills that will spawn and it will check the distance and spawn a coin randomly. Make sure to drag on the right components in the inspector. Like the coin prefab. I tested it with 3D objects but I think it will still work with 2D.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GroundDetector : MonoBehaviour
{
    // Make sure to assign this in the inspector so it knows what the coin should be.
    public GameObject Coin;
    //Change this in the inspector to determine how often it should try to spawn the coin.
    public float CheckSpawnRate;
    float countDown;
    Vector3 coinPos;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
        countDown -= 1f * Time.deltaTime;
        if (countDown <= 0f)
        {
            RandomCoin();
            countDown = CheckSpawnRate;
        }
    }
    public void RandomCoin()
    {
        //Check the "1" From 1 to any other number and that will determine how likely it is to spawn a coin.

        int r = Random.Range(0, 1);
        if (r == 0)
        {
            RaycastHit hit;
            //This is where it checks the ground height.
            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, Mathf.Infinity))
            {
                coinPos = hit.point;
                //The draw ray isn't required but it shows you a laser beam of where it is looking. Keep in mind it shoots from the bottom of the object the script is attatched to.
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * hit.distance, Color.yellow);
                Debug.Log("Did Hit");
            }
            Instantiate(Coin, coinPos, Quaternion.identity);
        }
    }
}