I want to move polygon object (cube, triangle, etc) when i click on specific tile of the object. How to do?
Try taking a look at Detect face of cube clicked - Questions & Answers - Unity Discussions
Think a “simple” way to do it would be to:
- detect which face was clicked and get the coordinates of it (x,y,z)
- compare the coordinates to the center coordinates of the cube and use that to figure out which way the cube should start moving
- can use static values for moving it by 1 block or probably just get the side from the cube object itself and then just move it 1 unit forward
Hope this helps in some way
The following code has worked for me.
TransparentObject.transform.position = hit.transform.position + hit.normal;
TransparentObject.transform.rotation = hit.transform.rotation;
Let me know if it worked for you or not.
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.A))
{
transform.Translate(0.1f, 0f, 0f);
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(-0.1f, 0f, 0f);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(0.0f, 0f, -0.1f);
}
if (Input.GetKey(KeyCode.W))
{
transform.Translate(0.0f, 0f, 0.1f);
}
}
}
this is the way to move