Question by
Bopian · Mar 14 at 07:50 PM ·
c#2dtopdownturn-based
Turnbased topdown 2D mouse movement
Hi. I am making a turned based game where i want the character to move to the spot the mouse clicks on. I have made that code but if you hold down the mouse button then the character keeps on moving towards the mouse, i want it to be turned based so i want the player to be unable to move unless the character has come to a stop.
Heres my code for the movement:
public void OnEnable()
{
if (Camera == null)
{
throw new InvalidOperationException("Camera not set");
}
}
public void Update()
{
if (FollowMouse || Input.GetMouseButton(0))
{
_target = Camera.ScreenToWorldPoint(Input.mousePosition);
_target.z = 0;
}
var delta = ShipSpeed * Time.deltaTime;
if (ShipAccelerates)
{
delta *= Vector3.Distance(transform.position, _target);
}
transform.position = Vector3.MoveTowards(transform.position, _target, delta);
}
Comment
Your answer
Follow this Question
Related Questions
Animation with different behaviors for different directions. 1 Answer
2D Sprite issue when rotating towards mouse click location. 2 Answers
Is there any way to trigger a popUp UI when a player steps in a specific set of tiles? 0 Answers
Orbit position controlled by mouse 2D (C#) 0 Answers
How do you add a Collider2D to a Line Renderer In Unity2D? 0 Answers