Instantiate Gameobject

Hello

i am trying to instantiate an a cylinder gameobject on a plane that has the coordinates of (0,1,0) using left mouse click, and after clicking left mouseclick on the instantiated cylinder a sphere will appear that is 3 unity on the right.

how can this work?

this is the code of cylinder instantiation :

if(Input.GetMouseButtonDown(0))
        {
             Camera c = GetComponent<Camera>();
            Ray r = c.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if(Physics.Raycast(r, out hit))
            {
                Transform hitObject = hit.transform;
                Capsule.transform.position = new Vector3(hit.point.x, 1.0f, hit.point.z);
                Instantiate(cylinder);
                
                
            
         } }

thank you

I’m not sure if this is what you want, but it works:

    public Camera myCamera;
    public GameObject cylinderPrefab;
    public Vector3 cylinderOffset = new Vector3(0, 1f, 0);
    public GameObject spherePrefab;
    public Vector3 sphereOffset = new Vector3(3f, 0, 0);

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = myCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                if (hit.transform.CompareTag("Untagged"))
                {
                    GameObject cylinder = Instantiate(cylinderPrefab);
                    cylinder.transform.position = hit.point + cylinderOffset;
                }
                else if (hit.transform.CompareTag("Cylinder"))
                {
                    GameObject sphere = Instantiate(spherePrefab);
                    sphere.transform.position = hit.transform.position + sphereOffset;
                }
            }
        }
    }