voidStart ()
{
rig2d = GetComponent ();
anim = GetComponentInChildren ();
jmpForce = JumpForce;
GameObject[ ] players = GameObject.FindGameObjectsWithTag(“Player”)
foreach(GameObjectplinplayers)
{
if (pl.transform != this.transform)
{
enemy = pl.transform;
}
}
}
voidUpdate()
{
AttackInput();
ScaleCheck();
OnGroundCheck();
Damage();
UpdateAnimator();
}
//voidAttackInput()
// {
//if(Input.GetButtonDown(“Attack1” = PlayerNumber.ToString())
// }
voidOnGroundCheck()
{
if (!onGround)
{
rig2d.gravityScale = 5;
}
else
{
rig2d.gravityScale = 1;
}
}
voidFixedUpdate ()
{
horizontal = Input.GetAxis (“Horizontal” + PlayerNumber.ToString ());
vertical = Input.GetAxis(“Vertical” + PlayerNumber.ToString());
Vector3movement = newVector3(horizontal, 0, 0);
crouch = (vertical < -0.1f);
if (vertical > 0.1f)
{
if (!jumpKey)
{
jmpDuration += Time.deltaTime;
jmpForce += Time.deltaTime;
if (jmpDuration < jumpDuration)
{
rig2d.velocity = newVector2(rig2d.velocity.x, jmpForce);
}
else
{
jumpKey = true;
}
}
}
if(!onGround && vertical < 0.1f)
{
falling = true;
}
if(attack[0] && !jumpKey || attack[1] && !jumpKey)
{
movement = Vector3.zero;
}
if (!crouch)
rig2d.AddForce (movement * maxSpeed);
else
rig2d.velocity = Vector3.zero;
}
voidScaleCheck()
{
if(transform.position.x < enemy.position.x)
transform.localScale = newVector3(-1,1,1);
else
transform.localScale = Vector3.one;
}
voidAttackInput()
{
if(Input.GetButtonDown(“Attack1” + PlayerNumber.ToString()))
{
attack[0] = true;
attacktimer[0] = 0;
timesPressed[0] ++;
}
if(attack[0])
{
attacktimer[0] += Time.deltaTime;
if(attacktimer[0] > attackRate || timesPressed[0] >=4)
{
attacktimer[0] = 0;
attack[0] = false;
timesPressed [0] = 0;
}
}
if(Input.GetButtonDown(“Attack2” + PlayerNumber.ToString()))
{
attack[1] = true;
attacktimer[1] = 0;
timesPressed[1] ++;
}
if(attack[1])
{
attacktimer[1] += Time.deltaTime;
if(attacktimer[1] > attackRate || timesPressed[1] >=4)
{
attacktimer[1] = 0;
attack[1] = false;
timesPressed [1] = 0;
}
}
}
voidDamage()
{
{
noDamageTimer += Time.deltaTime;
if (noDamageTimer > noDamage)
{
damage = false;
noDamgaeTimer = 0;
}
}
//if(!onGround)
//{
//rig2d.gravityScale = 10;
//Vector3dir = enemy.position - transform.position;
//rig2d.AddForce(-dir * 25);
//}
}
voidUpdateAnimator()
{
anim.SetBool (“Crouch”, crouch);
anim.SetBool (“OnGround”, this.onGround);
anim.SetBool (“Falling”, this.falling);
anim.SetFloat (“Movement”, Mathf.Abs(horizontal));
anim.SetBool (“Attack1”, attack [0]);
anim.SetBool (“Attack2”, attack[1]);
}
voidOnCollisionEnter2D(Collision2Dcol)
{
if (col.collider.tag == “Ground”)
{
onGround = true;
jumpKey = false;
jmpDuration = 0;
jmpForce = JumpForce;
falling = false;
}
}
voidOnCollisionExit2D(Collision2Dcol)
{
if (col.collider.tag == “Ground”)
{
onGround = false;
}
}
}