Create prfab when pressing a button

  1. please use the code tag ( Using code tags properly )

  2. I believe ‘Buttonprfab’ is a prefab in you assets and you assign it via the inspector?
    if so, Buttonprfab.transform.position will be whatever position the prefab was when you last saved it(you can select it and see what’s the value), it will never change on runtime.
    this makes the whole line

Vector3 ButtonPosition =
Camera.main.ScreenToWorldPoint(Buttonprfab.transform.position);

seems illogical to me.

  1. where are you calling this function? what i assume is you want to point somewhere in space with the mouse and click to spawn, what i see is only the option to plug this into an actual button UI on the scene.

  2. Does the coin spawn just not where you want it or does it not even instantiate?

pro tip: Debug.Log() is your friend.

  1. incase you wanted to point and click to spawn somewhere you need something like this:
void Update(){ //this runs every frame, as you should know

if(Input.GetMouseButtonDown(0)){//if the left(0) mouse button went from UP to DOWN in THIS frame(clicked down, not held)
Spawn();
}
}

but the current spawn doesn’t work for that.