How to unable player to move on GUI buttons
Hello Guys !
I cant solve problem with GUI and player movment.
When my character level up, i can click on button to increase damage or health. But, when i click on this button he moves to location behind button. How can i fix that ?
I make buttons by GUI.Button and use texture/Rect.
There is my mouse script : void Update() { cursorPosition(); if (!attack && !die) { if (Input.GetMouseButton(0)) { FindPosition(); } MoveToPosition(); } }
void FindPosition()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, 1000))
{
if (hit.collider.tag != "AllyMob" && hit.collider.tag != "Enemy")
{
position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
}
}
}
public void cursorPosition()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 1000))
{
mouseposition = hit.point;
}
}
void MoveToPosition()
{
if (Vector3.Distance(transform.position, position) > 2.2)
{
Quaternion Rotation = Quaternion.LookRotation(position - transform.position);
Rotation.x = 0f;
Rotation.z = 0f;
transform.rotation = Quaternion.Slerp(transform.rotation, Rotation, Time.deltaTime * 10);
controller.SimpleMove(transform.forward * speed);
GetComponent<Animation>().CrossFade(run.name);
}
else
{
GetComponent<Animation>().CrossFade(idle.name);
}
}
Your answer
Follow this Question
Related Questions
is there a way to ignore a click when i press on a button? 1 Answer
Limited response from mouse input in game view. 2019.3 0 Answers
Unity 3D: Third person movement and mouse camera control 0 Answers
Using MoveTowards to move GameObject from starting point to mouse cursor 0 Answers
Making GameObject move in the direction of my mouse (3d) 0 Answers