“Unity Movetowards” Ответ

Unity Movetowards

float speed;
Vector3 goalPosition;

void Update()
{
	transform.position = Vector3.MoveTowards(transform.position, goalPosition, speed * Time.deltaTime); //goes from the position of the gameObject to the goalPosition in a strait line with a speed of "speed"
  	//Also works with Vector2
}
Tartaud

двигаться к целевому единству

/// <summary>
/// Move 2D sprite towards target
/// </summary>
/// <param name="target"></param>
/// <param name="movementSpeed"></param>
private void Move(Vector3 target, float movementSpeed)
{
    //Move
    transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}
Legion

Как двигаться к единству объекта

//This will work for 2d or 3d platforms
//Make sure to call in Update or else it wont work
Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)
Ashton

Movetowards Unity

//put this in update method and disable rigidbody2d (gravity)
void Update()
{
transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}
MiniGeek

Ответы похожие на “Unity Movetowards”

Вопросы похожие на “Unity Movetowards”

Больше похожих ответов на “Unity Movetowards” по C#

Смотреть популярные ответы по языку

Смотреть другие языки программирования