public void OnTriggerEnter2D(Collider2D collider) { if (rabit) { GreenOrc greenOrc = collider.gameObject.GetComponent <GreenOrc> (); if (greenOrc != null) { if (greenOrc.isLive) { if (collider == greenOrc.body) { this.dead(); greenOrc.attack(); } else if (collider == greenOrc.head) { greenOrc.dead(); } } } } if (rabit) { BrownOrc brownOrc = collider.gameObject.GetComponent <BrownOrc> (); if (brownOrc != null) { if (brownOrc.isLive) { if (collider == brownOrc.head) { brownOrc.dead(); } } } } }
void Start() { orc = transform.parent.GetComponent <GreenOrc>(); }
float getDirection() { if (this.mode == Mode.Dead) { return(0); } Vector3 my_pos = this.transform.position; Vector3 rabit_pos = HeroRabit.current.transform.position; //attack if (rabit_pos.x > Mathf.Min(pointA.x, pointB.x) && rabit_pos.x < Mathf.Max(pointA.x, pointB.x)) { //this.anim.SetBool("run", true); mode = Mode.Attack; current = this; } //finish 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 rabit if (mode == Mode.Attack) { if (my_pos.x < rabit_pos.x) { return(1); } else { return(-1); } } //if a or b reached if (this.mode == Mode.GoToA) { if (my_pos.x <= pointA.x) { this.mode = Mode.GoToB; } } else if (this.mode == Mode.GoToB) { if (my_pos.x >= pointB.x) { this.mode = Mode.GoToA; } } //get new direction if (this.mode == Mode.GoToA) { if (my_pos.x <= pointA.x) { return(1); } else { return(-1); } } else if (this.mode == Mode.GoToB) { if (my_pos.x <= pointB.x) { return(1); } else { return(-1); } } return(0); }