Hi im wondering how to get my objects rotation right
I was using my preview objects rotation but if were to rotate it I would have to use quaternion euler
but when i use it this happens: 1
the object is rotated in the wrong orientation no matter what I do
My script
public void ChangeCurrentsBuilding()
{
//GameObject curprev = Instantiate(currentobject.preview, currentpos, currentobject.preview.transform.rotation) as GameObject;
GameObject curprev = Instantiate(currentobject.preview, currentpos, Quaternion.Euler(currentRot)) as GameObject;
currentpreview = curprev.transform;
}
public void startPreview()
{
if (Physics.Raycast(cam.position, cam.forward, out hit, 50, layer)) {
if (hit.transform != this.transform) {
showPreview(hit);
}
}
}
public void showPreview(RaycastHit hit2) {
currentpos = hit2.point;
currentpos -= Vector3.one * offset;
currentpos /= gridSize;
currentpos = new Vector3(Mathf.Round(currentpos.x), Mathf.Round(currentpos.y), Mathf.Round(currentpos.z));
currentpos *= gridSize;
currentpos += Vector3.one * offset;
currentpreview.position = currentpos;
if (Input.GetButtonDown("Fire2")) {
currentRot += new Vector3(0, 90, 0);
currentpreview.localEulerAngles = currentRot;
}
}
public void Build()
{
PreviewObject PO = currentpreview.GetComponent<PreviewObject>();
if(PO.isBuildable)
{
Instantiate(currentobject.prefab, currentpos, Quaternion.Euler(currentRot));
}
}
}
[System.Serializable]
public class buildObjects {
public string name;
public GameObject preview;
public GameObject prefab;
public int gold;
}