Hi,
Please help me on this.
I want to move a player from position A to position B. But before move the player object, I want to check that any object is on the path. If any object is on the path, then I should not move player, have to show error message. Position B is taken from mouse double click. Thank you .
- Need solution to check the object between position A and B before move.
- Please check my code, the way I handled the double click. If any other effective way to check, then please guide me.
Source Code:
private float doubleClickStart = 0;
bool dclick = false;
bool getclick = false;
void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
if ((Time.time - doubleClickStart) < 0.3f)
{
dclick = true;
getclick = true;
doubleClickStart = -1;
}
else
{
doubleClickStart = Time.time;
}
}
if (dclick)
this.OnDoubleClick();
}
void OnDoubleClick()
{
if (getclick)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
movement = hit.point;
}
getclick = false;
}
movePosition = Vector3.Lerp(transform.position, movement, Time.deltaTime * speed);
PlayerRightbody.MovePosition(movePosition);
}