Hello !
Iv’e made a script so I can instantiate a prefab at my current mouse position for my building game.
But right now the prefab only have one rotation and when I press “R” I want to rotate it 90 deg.
This is my current code for instantiating a prefab.
private Transform currentBuilding;
private Grid grid;
void Awake()
{
grid = FindObjectOfType<Grid>();
}
void Update()
{
if (currentBuilding != null)
{
Vector3 m = Input.mousePosition;
m = new Vector3(m.x, m.y, transform.position.y);
Vector3 p = grid.GetNearestPointOnGrid(GetComponent<Camera>().ScreenToWorldPoint(m));
currentBuilding.position = new Vector3(p.x, 0, p.z);
}
}
public void SetItem(GameObject b)
{
currentBuilding = ((GameObject)Instantiate(b)).transform;
}
Any ideas on how I can rotate the instantiated prefab?