Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Fosforus

Pages: [1]
1
Support / Re: Flipping the Sprite image in C# code
« on: November 01, 2013, 02:36:48 am »
Ok thanks, that worked perfectly. I spent a really long time on the internet trying to figure that out.

2
Support / Flipping the Sprite image in C# code
« on: November 01, 2013, 12:42:45 am »
I'm having trouble figuring out how to flip a sprite image in C# code. Take for example a character that moves left and right. At the moment I can't get the image to flip so when he is facing right or left, he is actually facing the corresponding direction. 

Here's the code I'm using so far.

Code: [Select]
using UnityEngine;
using System.Collections;

public class Movements : MonoBehaviour {

Vector3 movement;
private float moveSpeed = 15f;
private float moveDirX = 0f;
private float moveDirY = 0f;
private bool leftArrow;
private bool rightArrow;

private tk2dSpriteAnimator anim;
private bool walking = false;
private bool facingLeft = true;
private bool facingRight = false;


// Use this for initialization
void Start () {
anim = GetComponent<tk2dSpriteAnimator>();
}

// Update is called once per frame
void Update () {

bool leftArrow = Input.GetKey(KeyCode.LeftArrow);
bool rightArrow = Input.GetKey(KeyCode.RightArrow);
bool space = Input.GetKey(KeyCode.Space);

if(!leftArrow && !rightArrow)
{
if(moveDirX > 0)
moveDirX--;

if(moveDirX < 0)
moveDirX++;
anim.Play("Standing");
}

if(leftArrow) {
facingRight = false; facingLeft = true;

anim.Play ("Walk");
if(moveDirX > -moveSpeed)
  moveDirX -= 1f;
    }

    if(rightArrow) {
facingLeft = false; facingRight = true;
anim.Play ("Walk");

if(moveDirX < moveSpeed)
  moveDirX+= 1f;
    }

if(space){

}

movement = new Vector3(moveDirX, moveDirY, 0);
movement *= Time.deltaTime;
  transform.Translate(movement);
}
}
Also, is this the right place to post a question like this?

Pages: [1]