I have a script which has a “ghost object” of a object that will be instantiated, and I want to be able to rotate the ghost object and then instantiate with the same rotation as the ghostobject.
This is void Update()
if(Input.mousePosition != startingMousePosition)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.DrawLine( Camera.main.transform.position, hit.point, Color.red );
//rayHitPoint = hit.point;
Object1.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
if (Input.GetButton("RotateInst")){
Debug.Log ("RotateInst cliked");
Object1.transform.Rotate(Time.deltaTime, 1, 0);
}
}
And here is void RaycastToTerrain() (the important stuff)
RaycastHit hit;
Ray rayPos = Camera.main.ScreenPointToRay( Input.mousePosition );
if ( Physics.Raycast( rayPos, out hit, Mathf.Infinity ) )
{
Debug.DrawLine( Camera.main.transform.position, hit.point, Color.red );
rayHitPoint = hit.point;
}
if(Input.GetKeyDown(KeyCode.Mouse0)){
Debug.Log ("Instantiating Windmill.");
Instantiate(Object1, hit.point, Quaternion.identity);
}
As you can see in the Update function you press the button “RotateInst” (which is arrowkeys) to rotate the object. How do I give that rotation to the instantiate method?
Thanks!