Depending on the mouse movement (or position), the player sprite
Hi. As the title suggests, there is a problem in the process. I wrote the related script and the player object moved strangely.
I want to implement it like this video link. https://www.youtube.com/watch?v=TfvBhYF-6jI
public class playermove : MonoBehaviour { private Animator m_animator;
float mouse_x;
float mouse_y;
bool mode;
void Start()
{
m_animator = GetComponent<Animator>();
this.mouse_x = 1;
this.mouse_y = 1;
this.mode = false;
}
// Update is called once per frame
void Update()
{
float t_new_mouse_x = UnityEngine.Input.mousePosition.x;
float t_new_mouse_y = UnityEngine.Input.mousePosition.y;
bool t_mode;
if (t_new_mouse_x != this.mouse_x || t_new_mouse_y != this.mouse_y)
{
this.mouse_x = t_new_mouse_x;
this.mouse_y = t_new_mouse_y;
t_mode = true;
}
else
{
t_mode = false;
}
if (this.mode != t_mode)
{
this.mode = t_mode;
m_animator.SetBool("MouseMove", t_mode);
}
}
}
Can you tell me what's wrong with the script?
moveah.gif
(318.6 kB)
Comment
Your answer
Follow this Question
Related Questions
Help with 8-DOM Weapon Sprite Issue 0 Answers
Multiple Sprite Pivot Points 0 Answers
Should weapons be different sprites? 1 Answer
Sprite Animation via script C# 1 Answer