- Home /
Instantiate block at raycastHit, make it snap to whole numbers (make the raycasthit into a int)
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?
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);
}
}
}
Your answer
Follow this Question
Related Questions
How to activate a button? 1 Answer
Instantiate as a child? 3 Answers
Errors with Random Instantiate Script(Solved) 2 Answers
How do I instantiate objects above 'sealevel'? 1 Answer
Changing variable in a script of a game object hit with raycast 1 Answer