Hi there!
Figured I would ask for support here instead of the unity forum, just incase someone with the same problem might do a search for flipping. My searches did give some hits, but none that I could personally use because they were above my level.
I have an animation of a sprite for when he walks to the right. What I want is for it to be flipped when I walk to the left, but I can't seem to get it to work. I tried flipX and other recommendations but I am doing them completely wrong since they won't work. Could you explain to me how to flip them for when I do something in reverse direction and then add the line/lines in my code as it should be? I learn best by seeing how it is done and copying it. I have added my code as far as I have gotten here below. I have also tried adding sprite.scale but I must be missing something.
I understand that I can scale the x to -1, but I can't reach it by code. This line doesn't work.
gameObject.sprite.scale = new Vector3(-1,gameObject.transform.position.y, 0);
using UnityEngine;
using System.Collections;
public class Animations : MonoBehaviour {
//private bool walking = false;
private tk2dSpriteAnimator anim;
// Use this for initialization
void Start () {
anim = GetComponent<tk2dSpriteAnimator>();
}
//Go back to idle when nothing is pressed.
void HitCompleteDelegate(tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip)
{
anim.Play ("idle");
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.D))
{
anim.Play("walk");
anim.AnimationCompleted = HitCompleteDelegate;
}
if (Input.GetKey (KeyCode.A))
{
anim.Play("walk"); //I want the sprite play walk flipped. I tried adding sprite.scale *= (-1,1,1); here, but did not work.
anim.AnimationCompleted = HitCompleteDelegate;
}
}
}
Best regards,
Farzan Zand