I'm trying to rotate my character on the y axis 180 degrees, so he faces the direction he is facing. Side scroller game. The character move just will not face the other direction.
Thank you in advance.
using UnityEngine;
using System.Collections;
public class CharacterMovement : MonoBehaviour {
public float maxSpeed = 6.0f;
public bool facingRight = false;
public float moveDirection;
// Use this for initialization
void FixedUpdate ()
{
GetComponent().velocity = new Vector2 (moveDirection * maxSpeed, GetComponent().velocity.y);
if (moveDirection > 0.0f && !facingRight)
{
Flip();
}
else if (moveDirection < 0.0f && !facingRight)
{
Flip();
}
}
// Update is called once per frame
void Update ()
{
moveDirection = Input.GetAxis ("Horizontal");
}
void Flip()
{
facingRight = !facingRight;
transform.Rotate(Vector3.up, 180.0f, Space.World);
}
}
↧