Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player1Control : MonoBehaviour {
- public LayerMask playerMask;
- public GameObject target;
- public string currentAction = "Idle";
- public float speed = 12;
- public float jump = 7;
- public int damage=0;
- public bool isGrounded = false;
- public bool extraJump = false;
- public bool facingRight = true;
- public Transform myTrans;
- public Transform targTrans;
- public Transform ground;
- public Rigidbody myBody;
- public Rigidbody targBody;
- void Start() {
- myBody = this.GetComponent<Rigidbody>();
- myTrans = this.transform;
- targBody = target.GetComponent<Rigidbody>();
- targTrans = target.transform;
- ground = GameObject.Find(this.name + "/ground").transform;
- }
- void Update() {
- if(damage<0) damage=0;
- if(damage>999) damage=999;
- }
- void FixedUpdate() {
- isGrounded = Physics.Linecast (myTrans.position, ground.position, playerMask);
- if(isGrounded) extraJump=false;
- if(currentAction=="Idle"||currentAction=="Moving"||currentAction=="Jumping") Move(Input.GetAxisRaw("MoveDigital P1"));
- if(Mathf.Abs(Input.GetAxis("Horizontal P1"))>0.3&&Mathf.Abs(Input.GetAxis("Horizontal P1"))<0.7) { MoveSlow(Input.GetAxisRaw("Horizontal P1")); }
- if(Mathf.Abs(Input.GetAxis("Horizontal P1"))>=0.7) { Move(Input.GetAxisRaw("Horizontal P1")); }
- if(Input.GetButtonDown("Jump P1")) {
- Jump();
- }
- if(!isGrounded) { myBody.velocity += Vector3.down; currentAction="Jumping"; }
- if(isGrounded&&!Input.GetButtonDown("Jump P1")&&Mathf.Abs(Input.GetAxis("Horizontal P1"))<0.3&&Mathf.Abs(Input.GetAxisRaw("MoveDigital P1"))<0.3&¤tAction!="Neutral A"&&Input.GetAxisRaw("VerticalDigital P1")==0) {
- currentAction="Idle";
- }
- if(isGrounded&&Input.GetAxisRaw("VerticalDigital P1")==-1) { currentAction="Crouch Smash"; }
- if(isGrounded&&Input.GetAxisRaw("VerticalDigital P1")==1) { currentAction="20XX"; }
- // print(Input.GetAxisRaw("VerticalDigital P1"));
- if(isGrounded&&Input.GetAxis("Vertical P1")<0.7&&Input.GetAxis("Vertical P1")>0.3) currentAction="NoJohns";
- if(isGrounded&&Input.GetAxis("Vertical P1")>=0.7) currentAction="20XX";
- if(isGrounded&&Input.GetAxis("Vertical P1")>-0.7&&Input.GetAxis("Vertical P1")<-0.3) currentAction="Crouching";
- if(isGrounded&&Input.GetAxis("Vertical P1")<=-0.7) currentAction="Crouch Smash";
- if(currentAction=="Idle"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Neutral"); }
- if(currentAction=="Moving Slow"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Side"); }
- if(currentAction=="NoJohns"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Up"); }
- if(currentAction=="Crouching"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Down"); }
- if(currentAction=="Moving"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Side"); }
- if(currentAction=="20XX"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Up"); }
- if(currentAction=="Crouch Smash"&&Input.GetButtonDown("Normal Attack P1")) { Normal("Down"); }
- }
- public void Move(float hInput) {
- currentAction="Moving";
- if(hInput>0) facingRight=true;
- if(hInput<0) facingRight=false;
- Vector3 hspd = myBody.velocity;
- hspd.x = hInput*speed;
- myBody.velocity = hspd;
- }
- public void MoveSlow(float hInput) {
- currentAction="Moving Slow";
- if(hInput>0) facingRight=true;
- if(hInput<0) facingRight=false;
- Vector3 hspd = myBody.velocity;
- hspd.x = (hInput*speed)/4;
- myBody.velocity = hspd;
- }
- public void Jump() {
- if(isGrounded) { myBody.velocity = Vector3.zero; myBody.AddForce(transform.up*jump*5, ForceMode.Impulse); extraJump=true; return; }
- if(extraJump) { myBody.velocity = Vector3.zero; myBody.AddForce(transform.up*jump*5, ForceMode.Impulse); extraJump=false; return; }
- }
- public void Damage(string attack, string direction) {
- if(attack=="Normal") {
- if(direction=="neutral") {
- targBody.velocity = Vector3.zero;
- if(facingRight) {
- Vector3 newVel = new Vector3(target.GetComponent<Player1Control>().damage*6, target.GetComponent<Player1Control>().damage*2, 0);
- targBody.AddForce(newVel, ForceMode.Acceleration);
- print("Stuff");
- }
- if(!facingRight) {
- targBody.AddForce(transform.up*-1*target.GetComponent<Player1Control>().damage/16, ForceMode.Impulse);
- targBody.AddForce(transform.right*-1*target.GetComponent<Player1Control>().damage, ForceMode.Impulse);
- print("Other Stuff");
- }
- target.GetComponent<Player1Control>().damage+=3;
- }
- }
- }
- public void Normal(string direction) {
- float distance = Vector3.Distance(target.transform.position, transform.position);
- if(direction=="Neutral") {
- if (distance < 1.3f) {
- if (distance > 0 && ((facingRight==true&&targTrans.position.x>myTrans.position.x)||(facingRight==false&&targTrans.position.x<myTrans.position.x))) {
- print("Neutral A");
- Damage("Normal","neutral");
- }
- }
- }
- else if(direction=="Side") {
- if (distance < 2f) {
- if (distance > 0 && ((facingRight==true&&targTrans.position.x>myTrans.position.x)||(facingRight==false&&targTrans.position.x<myTrans.position.x))) {
- print("Side A");
- target.GetComponent<Player1Control>().damage+=2;
- }
- }
- }
- else if(direction=="Up") {
- if (distance < 1.3f) {
- if (distance > 0 && ((facingRight==true&&targTrans.position.x>myTrans.position.x)||(facingRight==false&&targTrans.position.x<myTrans.position.x))) {
- print("Up A");
- target.GetComponent<Player1Control>().damage+=3;
- }
- }
- }
- else if(direction=="Down") {
- if (distance < 1.6f) {
- if (distance > 0 && ((facingRight==true&&targTrans.position.x>myTrans.position.x)||(facingRight==false&&targTrans.position.x<myTrans.position.x))) {
- print("Down A");
- target.GetComponent<Player1Control>().damage+=4;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement