Skip to content

Instantly share code, notes, and snippets.

@imranismail
Last active Aug 29, 2015
Embed
What would you like to do?
2D Platformer Experimentation in Unity Game Engine. Visit this link to try it out http://goo.gl/QHT6pp

#README Please visit this link to try it out http://goo.gl/QHT6pp You have to have unity web player installed though

#pragma strict
var dashButton = "Fire1";
var dashPower : float = 300f;
var facingRight : boolean = false;
function Start () {
}
function Update () {
if (Input.GetButtonDown(dashButton))
{
var move : float = Input.GetAxis("Horizontal");
if(move > 0)
{
rigidbody2D.AddForce(transform.right * dashPower);
}
else if (move < 0)
{
rigidbody2D.AddForce(transform.right * dashPower * -1);
}
}
}
#pragma strict
var jumpButton = "Jump";
var jumpPower : float = 650.0f;
var animator : Animator;
var groundCheck : Transform;
var minJumpDelay : float = 0.5f;
var jumpTime : float = 0.0f;
function Start () {
animator = gameObject.GetComponent(Animator);
}
function Update () {
animator.SetBool('Grounded', Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")));
if (jumpTime > 0)
{
jumpTime -= Time.deltaTime;
}
if (Input.GetButtonDown(jumpButton) && animator.GetBool("Grounded"))
{
animator.SetBool("Jump", true);
rigidbody2D.AddForce(transform.up * jumpPower);
jumpTime = minJumpDelay;
}
if (animator.GetBool('Grounded') && jumpTime <= 0 && animator.GetBool('Jump'))
{
animator.SetBool("Jump", false);
}
#pragma strict
var speed : float;
var axisName = "Horizontal";
var anim : Animator;
function Start () {
}
function Awake () {
anim = GetComponent(Animator);
}
function Update () {
anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis(axisName)));
if (Input.GetAxis(axisName) < 0)
{
transform.localScale.x = -1.0f;
}
else if (Input.GetAxis(axisName) > 0)
{
transform.localScale.x = 1.0f;
}
transform.position += transform.right * Input.GetAxis(axisName) * speed * Time.deltaTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment