You are viewing our Forum Archives. To view or take place in current topics click here.
Unity 2D game | Need Help !
Posted:

Unity 2D game | Need Help !Posted:

Sif-
  • 2 Million
Status: Offline
Joined: Nov 23, 201311Year Member
Posts: 1,399
Reputation Power: 232
Status: Offline
Joined: Nov 23, 201311Year Member
Posts: 1,399
Reputation Power: 232
So i started to make a new game like a top down pixel game for a school project and i can get the script to walk up and down, i only have left to right :s
I wanna make all the animations play when their button is pressed
W - UP
S - DOWN
A - LEFT
D -RIGHT

Here is my script for it


using UnityEngine;
using System.Collections;

public class HeroMove : MonoBehaviour {

public float Speed = 2;
Animator anim;

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

// Update is called once per frame
void FixedUpdate ()
{
rigidbody2D.velocity = new Vector2 (Input.GetAxis("Horizontal") * Speed, 0);
anim.SetFloat ("hSpeed", Mathf.Abs (rigidbody2D.velocity.x));

if (rigidbody2D.velocity.x > 0 && transform.localScale.x < 0)
transform.localScale = new Vector3 (1, 1, 1);
if (rigidbody2D.velocity.x < 0 && transform.localScale.x > 0)
transform.localScale = new Vector3 (-1, 1, 1);
}
}


It is coded in C# and i really need help, i have other codes working in javascript but i wanted this to be a different coding language

So yeah help me if you can and i will give rep
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.