- Home /
Question by
Jojo120120 · Apr 10, 2018 at 05:55 PM ·
animationrotationposition2d-platformer
Unity 2D Sprite position mirror on character
I'm totally new with Unity and started to try to make a 2D sidescroller game. When ich move with my character in the opposite direction I wrote a script which mirrors the used sprites on position. This script I added to every component of my character (body, head, left feet, right feet). With the body and the head there is no issue but by both feets I have to change position too (for the animation to work right). How can I do this? Change rotation and position? I know for the most users this might be a simple question but like I said, I'm a absolut beginner.
Here my Code to rotate:
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class CDWeapon : MonoBehaviour {
public bool lookingRight = true;
public float hor;
// Use this for initialization
void Start () {
hor = Input.GetAxis("Horizontal");
}
// Update is called once per frame
void Update () {
float hor = Input.GetAxis("Horizontal");
if ((hor > 0 && !lookingRight) || (hor < 0 && lookingRight))
Flip();
}
void Flip()
{
lookingRight = !lookingRight;
Vector3 myScale = transform.localScale;
myScale.x *= -1;
transform.localScale = myScale;
}
}
Comment