Placing and rotating dominoes?
So I have a game where you place dominoes and tip them, pretty simple. I currently have a script to place my dominoes, but I can't rotate them, nor can I see where they're going to be placed. Maybe a transparent domino prefab that follows cursor until clicking?
Thanks in advance :)
My current code is here
var prefab : Transform; function Update(){ if(Input.GetMouseButtonUp(0)){ var ray : Ray = GetComponent.().ScreenPointToRay (Input.mousePosition); var hit : RaycastHit;
if (Physics.Raycast(ray, hit,Mathf.Infinity)){
if(hit.collider.tag == "Terrain"){
var placePos : Vector3 = hit.point;
placePos.y += .5;
placePos.x = Mathf.Round(placePos.x);
placePos.z = Mathf.Round(placePos.z);
Instantiate (prefab, placePos, Quaternion.identity);
}
}
}
}
Answer by StinkyDubeau · Dec 12, 2016 at 02:03 AM
Alrighty, after a while of messing around I managed to figure out a bit of a solution. Still no preview of the placement but at least I can rotate. I just attached this script to something in my hierarchy and now I can middle-click to rotate 45 degrees. :)
pragma strict
function Start () {
}
function Update () { if (Input.GetMouseButtonDown(2)) { var hit : RaycastHit; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, hit)) { if (hit.collider.tag == "domino") hit.collider.transform.Rotate(0,45,0); } }
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612102520im_/https://answers.unity.com/themes/thub/images/avi.jpg)