- Home /
Unity 2D Platformer Enemy flipping
I am making a 2d platformer and i want it so when the enemy is walking right its facing right and the same with left if someone can send me the code and tell me were to put it that would be great thx.
Answer by belvita · Nov 30, 2013 at 09:01 AM
i will help u but please vote me i help so many people but they do not appreciate thanx .attach this to the gameobject u wanna flip change the buttons a or d how u want.
using UnityEngine; using System.Collections;
public class flip : MonoBehaviour {
private float X; private Vector3 position;
// Use this for initialization void Start () {
X=transform.localScale.x;
position=transform.localScale;
}
// Update is called once per frame void Update () {
if(Input.GetKey("a"))
{
position.x=X;
//flip the texture
transform.localScale = position;
}
else if(Input.GetKey("d"))
{
position.x=-X;
//flip the texture
transform.localScale = position;
}
}
}
this didnt help at all and could this be in javascipt please and i voted
This is why no one votes your question. "No it must be inside a c# script". Also, format your code. Not gonna get a vote unless you fix those things. Also for the other dude. REALLY? ARE YOU REALLY GONNA AS$$anonymous$$ FOR IT IN JAVASCRIPT? HE WROTE YOU AN ENTIRE SCRIPT AND YOU SHOW NO EFFORT IN TRYING TO ACCO$$anonymous$$PLISH THIS YOURSELF. DANG. SO SELFISH. LEARN TO CODE AND PUT SO$$anonymous$$E EFFORT INTO THIS.
Your answer
Follow this Question
Related Questions
Why is my gameObject falling so slow? 1 Answer
animation 2d platformer 2 Answers
Damaging Enemies 1 Answer
AI & pathfinding for 2D platformer - how to approach? 0 Answers