private void Awake() { m_Character = GetComponent <characterbehavior>(); // edit player's money playerstatics.money = 0; playerstatics.health = m_Character.health; }
private void FixedUpdate() { // ground judge grounded = false; Vector2 colliderBoxSize = new Vector2(Mathf.Abs(transform.lossyScale.x * 2f), Mathf.Abs(transform.lossyScale.y * 2f)); Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position, colliderBoxSize, 0f, LayerMask.GetMask("ground")); for (int i = 0; i < colliders.Length; i++) { float colliderTopPos = colliders[i].transform.position.y + colliders[i].transform.lossyScale.y; float characterBottomPos = transform.position.y - transform.lossyScale.y; if (colliders[i].gameObject != gameObject && characterBottomPos >= colliderTopPos) { grounded = true; } } // hit && damage judge colliders = Physics2D.OverlapBoxAll(transform.position, colliderBoxSize, 0f, LayerMask.GetMask("hitboxes")); for (int i = 0; i < colliders.Length; i++) { // process order: // abyssfall -> instadead -> footstool judge -> punch judge -> basedmg judge // abyssfall judge if (colliders[i].gameObject.tag == "AbyssHitbox") { playerstatics.health = 0; Destroy(gameObject); m_Cam.starshaking(); } // footstool judge else if ((gameObject.tag == "Player" && colliders[i].gameObject.tag == "EnemyFastfallHitbox") || (gameObject.tag == "Enemy" && colliders[i].gameObject.tag == "PlayerFastfallHitbox")) { characterbehavior tempobject = colliders[i].GetComponentInParent <characterbehavior>(); if (tempobject != null && !damageinv && !moveInv) { // footstool to differernt character should behaves variably. // now footstool kills enemy instantly but no effect on player // now character in footstool anim has moveinv tempobject.footstooledOnSth = true; inFootstooled = true; m_Anim.SetTrigger("Footstooled"); lastFootstooledTime = Time.time; } } // punch judge else if ((gameObject.tag == "Player" && colliders[i].gameObject.tag == "EnemyPunchHitbox") || (gameObject.tag == "Enemy" && colliders[i].gameObject.tag == "PlayerPunchHitbox")) { characterbehavior tempobject = colliders[i].GetComponentInParent <characterbehavior>(); if (tempobject != null && !damageinv && !moveInv) { if ((facingright && tempobject.facingright) || (!facingright && !tempobject.facingright)) { turnaround(); } // face to the character who's punching it damageinv = ingetPunchedRecovery = true; damageInvStartTime = getpunchedRcoStartTime = Time.time; curGetPunchedSpd = tempobject.getpunchspd(); curGetPunchedRecoveryTime = tempobject.getpunchrcotime(); m_Anim.SetTrigger("Damaged"); } break; } // base damage judge else if ((gameObject.tag == "Player" && colliders[i].gameObject.tag == "EnemyBaseHitbox") || (gameObject.tag == "Enemy" && colliders[i].gameObject.tag == "PlayerBaseHitbox")) { if (!damageinv && !moveInv) { // enemy do have invincible frames now if (health > damagePerHit) { health -= damagePerHit; damageinv = inBaseDamageRecovery = true; damageInvStartTime = baseDamagedRcoStartTime = Time.time; m_Anim.SetTrigger("Damaged"); } else { health = 0; deadAnimStartTime = Time.time; inDeadAnimPlay = true; m_Anim.SetTrigger("Normaldie"); } } break; } } if (inDeadAnimPlay) { characterdeadprocess(); } else if (inDash) { dashprocess(); } else if (inFastfall || inSpawn) { fastfallandspawnprocess(); } else if (inPunch) { punchprocess(); } else if (inBaseDamageRecovery) { basedamagercoprocess(); } else if (ingetPunchedRecovery) { getpunchedrcoprocess(); } else if (inFootstooled) { getfootstooledprocess(); } // get out from damageinv if time if (Time.time > damageInvStartTime + damageInvcibileTime && damageinv) { damageinv = false; Vector3 tempPos = new Vector3(transform.position.x, transform.position.y, 0f); // original z position is 0 transform.position = tempPos; } }
// Use this for initialization void Awake() { m_anim = GetComponent <Animator>(); m_player = GameObject.FindGameObjectWithTag("Player").GetComponent <characterbehavior>(); }
private void Awake() { m_Character = GetComponent <characterbehavior>(); }