In my Unity 2D project i wanted to make a drone, that follows the mouse cursor, but it didn´t worked. The drone always followed me, but not the cursor. Then I wrote this script to find the error, but I cant find anything. Please help me
The script:
public class hardtdrone : MonoBehaviour
{
public float speed;
Vector3 mousePos;
void Start(){
}
void Update(){
MoveDrone();
}
void MoveDrone(){
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - Camera.main.transform.position;
mousePos.z = 10;
if(transform.position.x < mousePos.x){
//go right
Debug.Log("right");
}
else if(transform.position.x > mousePos.x){
//go left
Debug.Log("left");
}
if(transform.position.y < mousePos.y){
//go up
Debug.Log("up");
}
else if(transform.position.y > mousePos.y){
//go down
Debug.Log("down");
}
}
}