I’m creating a Sim City/City Skylines style game. I am trying to allow the player to place a building at the mouse position, however the buildings always appear at the player’s position, not the mouse position. I have no idea what’s going on. As far as I know, my building place script should not allow this.
Here is the code of my BuildingPlaceHandler.cs:
public class PlaceBuildingHandler : MonoBehaviour {
public GameObject AVGNApartments;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
var worldMousePosition = Camera.main.ScreenToWorldPoint(new
Vector3(Input.mousePosition.x, 30, Input.mousePosition.z));
Instantiate(AVGNApartments, worldMousePosition, gameObject.transform.rotation);
}
}
}
Note: 30 is the height of my terrain.
Why is it placing buildings at the player vs. the mouse position?