How do i make so my script detects when my player is moving? Please help me! I have tried everything... Code (CSharp): using UnityEngine; using System.Collections; public class Knight : MonoBehaviour { void DetectPlayerMoving() { //insert code here }
Erm... is the Knight script attached to a GameObject with a rigidbody? If so all you need to do is get the rigidbody with GetComponent<Rigidbody2D>() in Start and store it in a global variable, then check in FixedUpdate if the magnitude of it's velocity is larger than some threshold.
If it only moves ones then You could have a moving variable that you enable in your movement code. Then you could set it to false in update if it isn't already code: Code (CSharp): bool moving = false; // Add this to movement code: moving = true void Update() { if(moving == true){ moving = false; } } Hope this helps!