Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityStandardAssets.CrossPlatformInput;
- public class CharacterController : MonoBehaviour {
- //PAC-16-8895266-2043887
- public float speed;
- public AudioClip hitSwoosh;
- private Rigidbody2D rb;
- private AudioSource playerSounds;
- private Animator anim;
- private bool facingRight;
- private string[] whichAttack = {"isAttacking", "isAttacking2", "isAttacking3"};
- protected bool isAttacking = false;
- protected bool isMoving = false;
- //protected bool comboOneDone = false;
- //protected bool comboTwoDone = false;
- // Use this for initialization
- void Start () {
- rb = GetComponent<Rigidbody2D>();
- anim = transform.GetChild (0).GetComponent<Animator>();
- playerSounds = GetComponent<AudioSource>();
- facingRight = true;
- }
- void Update(){
- if(CrossPlatformInputManager.GetButtonDown ("Attack")){
- isAttacking = true;
- }
- }
- // Update is called once per frame
- void FixedUpdate () {
- float horizontal = CrossPlatformInputManager.GetAxis ("Horizontal");
- if(isAttacking == false){
- MoveControl (horizontal);
- }
- Flip (horizontal);
- HandleAttack ();
- Reset ();
- }
- void MoveControl(float horizontal){
- if(!anim.GetCurrentAnimatorStateInfo(0).IsTag("Attack")){
- rb.velocity = new Vector2(horizontal * speed, 0);
- anim.SetFloat ("speed", Mathf.Abs (horizontal));
- print (horizontal);
- }
- }
- void Flip(float horizontal){
- if(horizontal > 0 && !facingRight || horizontal < 0 && facingRight){
- facingRight = !facingRight;
- Vector3 theScale = transform.localScale;
- theScale.x *= -1;
- transform.localScale = theScale;
- }
- }
- void HandleAttack(){
- if(isAttacking && !anim.GetCurrentAnimatorStateInfo(0).IsTag("Attack")){
- rb.velocity = Vector2.zero;
- anim.SetTrigger (whichAttack[Random.Range (0, 3)]);
- /*playerSounds.clip = hitSwoosh;
- playerSounds.Play();
- if(!comboOneDone){
- comboOneDone = true;
- anim.SetTrigger (whichAttack[0]);
- comboTwoDone = false;
- }else if(!comboTwoDone && comboOneDone){
- comboTwoDone = true;
- anim.SetTrigger (whichAttack[1]);
- }else if(comboOneDone && comboTwoDone){
- anim.SetTrigger (whichAttack[2]);
- comboOneDone = false;
- }
- Debug.Log (comboOneDone);
- Debug.Log (comboTwoDone);*/
- }
- }
- void Reset(){
- isAttacking = false;
- }
- }
Add Comment
Please, Sign In to add comment