Question by
fluxhackspro · Aug 17, 2016 at 07:44 AM ·
instantiateraycastint
Instantiate block at raycastHit, make it snap to whole numbers (make the raycasthit into a int) REUPLOAD
Hello, so i got into a problem when i was developing my game. Im trying to place blocks in a world that is also made out of blocks. But when i instantiate the block it gets placed in between the other blocks. For example it gets placed at a position like this: 152.8921, 5.2311, 982.8108 I want it to be placed in whole numbers (int). So its position whould rather be this: 152, 5, 982 (make it snap to whole numbers) Is there a way to do this?
NOTE This is a reupload ofmy old post it didnt get approved or commented on by moderators
Sorry for my bad english and i hope you understand what im going for. Thanks
here is my script:
public Transform Block1;
void Update ()
{
if (Input.GetMouseButtonDown (1))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2.0f, Screen.height/2.0f, 0));
if(Physics.Raycast(ray, out hit, 5.0f) && hit.transform.tag == "BlockyStone")
{
Instantiate(Block1, hit.point, Quaternion.identity);
}
}
}
Comment