public void OnTriggerEnter2D(Collider2D collider) { if (this.health > 0) { Orc1 orc = collider.gameObject.GetComponent <Orc1> (); Orc2 orc2 = collider.gameObject.GetComponent <Orc2> (); if (orc != null) { if (!orc.isDead()) { if (collider == orc.bodyCollider) { this.removeHealth(1); orc.attackRabit(); } else if (collider == orc.headCollider) { orc.removeHealth(1); } } } if (orc2 != null) { if (!orc2.isDead()) { if (collider == orc2.headCollider) { orc2.removeHealth(1); } } } } }
// NEW CODE public void OnTriggerEnter2D(Collider2D collider) { if (this.CurrentHealth > 0 && orcIsDead == false) { Orc1 orc = collider.gameObject.GetComponent <Orc1> (); if (orc != null) { if (collider == orc.bodyCollider) { Debug.Log("body!!!!!!!!!!!!!!!"); this.reduceHealth(3); } if (collider == orc.headCollider) { Debug.Log("head!!!!!!!!!!!"); orcIsDead = true; orc.reduceHealth(3); } } } }
float getDirection() { if (this.mode == Mode.Dead) { return(0); } Vector3 my_pos = this.transform.position; Vector3 rabit_pos = HeroRabit.current.transform.position; //start attack if (rabit_pos.x > Mathf.Min(pointA.x, pointB.x) && rabit_pos.x < Mathf.Max(pointA.x, pointB.x)) { mode = Mode.Attack; current = this; Debug.Log("current orc set"); } //end attack if (mode == Mode.Attack && !(rabit_pos.x > Mathf.Min(pointA.x, pointB.x) && rabit_pos.x < Mathf.Max(pointA.x, pointB.x))) { mode = Mode.GoToA; } //if attack, move to the rabbit if (mode == Mode.Attack && !HeroRabit.current.isDead()) { if (my_pos.x < rabit_pos.x) { return(1); } else { return(-1); } } //change mode if a or b reached if (this.mode == Mode.GoToB) { if (my_pos.x >= pointB.x) { this.mode = Mode.GoToA; } } else if (this.mode == Mode.GoToA) { if (my_pos.x <= pointA.x) { this.mode = Mode.GoToB; } } //get new direction if (this.mode == Mode.GoToB) { if (my_pos.x <= pointB.x) { return(1); } else { return(-1); } } else if (this.mode == Mode.GoToA) { if (my_pos.x <= pointA.x) { return(1); } else { return(-1); } } return(0); }