//Define Component References private void OnEnable() { trans = GetComponent <Transform>(); anim = GetComponent <Animator>(); pm = GetComponent <scr_placeMeeting>(); po = GetComponent <scr_physicsObject>(); enemy = GetComponent <scr_enemy>(); }
//Define Component Variables private void OnEnable() { trans = GetComponent <Transform>(); po = GetComponent <scr_physicsObject>(); pm = GetComponent <scr_placeMeeting>(); enemy = GetComponent <scr_enemy>(); player = GameObject.Find("obj_player").GetComponent <Transform>(); mainCam = GameObject.Find("obj_playerCamera").GetComponent <Transform>(); }
// Update is called once per frame void Update() { //Manage Attack Scale trans.localScale = scale; //Check For Collisions With Enemies if (pm.PlaceMeeting(trans.position.x, trans.position.y, 2)) { //Get List Of Colliding Enemies Physics2D.OverlapCollider(bc2d, contactFilter, collideList); //Check For All Colliding Enemies for (int i = 0; i < collideList.Length; i++) { //Reset Instance Checked Variable bool instRegistered = false; //Check If Collision Instance Exists if (collideList[i] != null) { //Check If Collision Instance Is An Enemy if (collideList[i].gameObject.GetComponent <scr_enemy>() != null) { //Check If Enemy Is Alive if (collideList[i].gameObject.GetComponent <scr_enemy>().dead == false) { //Check If Instance Has Already Been Registered for (int p = 0; p < usedCollideList.Length; p++) { if (collideList[i] == usedCollideList[p]) { /*Debug.Log("COMPARISON"); * Debug.Log(collideList[i]); * Debug.Log(usedCollideList[p]);*/ instRegistered = true; break; } } //Register Instance If Not Registered Already if (!instRegistered) { for (int p = 0; p < usedCollideList.Length; p++) { //Check For First Null Instance To Register if (usedCollideList[p] == null) { //Register Collision usedCollideList[p] = collideList[i]; //Determine Hit Direction //if (!sr.flipX) hitDir = 1; //else hitDir = -1; //Determine Hit Direction From Player Relation (EDGECASE GLITCH ON FIRST FRAME) if (trans.position.x > player.position.x) { hitDir = 1; } else if (trans.position.x < player.position.x) { hitDir = -1; } //INTERACT WITH ENEMY scr_enemy hitEnemy = collideList[i].GetComponent <scr_enemy>(); hitEnemy.GetHit(hitDir); //Calls Method Built In Enemy //Debug.Log(hitEnemy); //Debug.Log("Enemy Hit From Player Attack"); //Break break; } } } } } } } }//ENEMY COLLISION CHECK //Write Out usedCollideList //WriteUsedCollisionList(); /* * void ResetCollideArray() * { * //Reset Values Of The Used Enemy Collision List * for (int i = 0; i < usedCollideList.Length;i++) * { * usedCollideList[i] = null; * } * }*/ }