Skip to content
Permalink
e13c256101
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
82 lines (56 sloc) 2.42 KB
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Player))]
public class PlayerInput : MonoBehaviour
{
Player player; //reference to player script
private Rigidbody2D m_Rigidbody2D;
public static bool m_FacingRight = true; // For determining which way the player is currently facing.
public Transform attackPoint; //point of attack
public Transform leftattackPoint; //point of attack
public Transform rightattackPoint; //point of attack
public SpriteRenderer mySpriteRenderer; //to flip
public Animator animator;
private void Awake ()
{
m_Rigidbody2D = GetComponent<Rigidbody2D>();
}
void Start()
{
player = GetComponent<Player>();
}
void Update()
{
Vector2 directionalInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); //
player.SetDirectionalInput(directionalInput); //pass in directional input
attackPoint.position = new Vector3(attackPoint.position.x, attackPoint.position.y, attackPoint.position.z);
leftattackPoint.position = new Vector3(leftattackPoint.position.x, leftattackPoint.position.y, attackPoint.position.z);
rightattackPoint.position = new Vector3(rightattackPoint.position.x, rightattackPoint.position.y, attackPoint.position.z);
//run animation
animator.SetFloat("Speed", Mathf.Abs(Input.GetAxisRaw("Horizontal")));
if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) //space down
{
if (mySpriteRenderer != null)
{
// flip the sprite
mySpriteRenderer.flipX = true;
attackPoint.position = new Vector3(leftattackPoint.position.x, leftattackPoint.position.y, attackPoint.position.z);
m_FacingRight = false;
}
}
if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) //space down
{
mySpriteRenderer.flipX = false;
attackPoint.position = new Vector3(rightattackPoint.position.x, attackPoint.position.y, attackPoint.position.z);
m_FacingRight = true;
}
if (Input.GetKeyDown(KeyCode.Space)) //space down
{
player.OnJumpInputDown(); //call this method
}
if (Input.GetKeyUp(KeyCode.Space)) //release
{
player.OnJumpInputUp(); //call this method
}
}
}