Answer the question
In order to leave comments, you need to log in
How to speed up the movement speed of a sprite in Unity?
I’m making a simple mobile phone on the unit, I added a rat and set a private float speed of 10 for it, I also made it so that it does not go beyond -2.5 and 2.5. The mouse did not go beyond the borders, everything worked, there was also a problem that if I tap to any place, then the sprite will immediately move there, I fiskil. Here is the code
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
public Transform player;
[SerializeField]
private float speed = 10f;
void OnMouseDrag () {
Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mousePos.x = mousePos.x > 2.5f ? 2.5f : mousePos.x;
mousePos.x = mousePos.x < -2.5f ? -2.5f : mousePos.x;
player.position = Vector2.MoveTowards (player.position,
new Vector2 (mousePos.x, player.position.y),
speed = Time.deltaTime);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question