- Home /
Question by
bobrovapaula · Apr 18, 2019 at 01:40 PM ·
sprite2d gameflip
How can I flip my sprite on the X axis when it reaches the target?
using System.Collections;
using UnityEngine;
public class Ship_move : MonoBehaviour
{
public Transform[] target;
public float speed;
private int current;
// Update is called once per frame
void Update()
{
if (transform.position != target[current].position)
{
Vector2 pos = Vector2.MoveTowards(transform.position, target[current].position, speed * Time.deltaTime);
GetComponent<Rigidbody2D>().MovePosition(pos);
}
else current = (current + 1) % target.Length;
}
}
Comment