- Home /
how to flip a sprite using touchpad input
Hi I'm new to game development and making my first game
A have been using the unity tutorials to help me a lot and came across an issue of how to flip my sprite when moving it in different direction.
The code from the tutorial was:
MOBILE DEVELOPMENT: CONVERTING SPACE SHOOTER TO MOBILE
BEGINNER LIVE TRAINING ARCHIVE
To download the "Mobile Artwork" for this session please use the link [HERE].
SimpleTouchPad
Expand view
Copy codeC#
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
public class SimpleTouchPad : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler {
public float smoothing;
private Vector2 origin;
private Vector2 direction;
private Vector2 smoothDirection;
private bool touched;
private int pointerID;
void Awake () {
direction = Vector2.zero;
touched = false;
}
public void OnPointerDown (PointerEventData data) {
if (!touched) {
touched = true;
pointerID = data.pointerId;
origin = data.position;
}
}
public void OnDrag (PointerEventData data) {
if (data.pointerId == pointerID) {
Vector2 currentPosition = data.position;
Vector2 directionRaw = currentPosition - origin;
direction = directionRaw.normalized;
}
}
public void OnPointerUp (PointerEventData data) {
if (data.pointerId == pointerID) {
direction = Vector3.zero;
touched = false;
}
}
public Vector2 GetDirection () {
smoothDirection = Vector2.MoveTowards (smoothDirection, direction, smoothing);
return smoothDirection;
}
}
I'm just trying to figure out the best way to flip my sprite. Before implementing touch I used a if transform = -1 flip method but that doesn't seem to work
Any ideas?
Comment
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to do a sprite flip 1 Answer
Sprite flip movement script not working! HELP! 0 Answers
LocalScale not working idealy 1 Answer