// Update is called once per frame void Update() { //check if (Vector3.Distance(gameStatusOp.getHeroPosition().position, gameObject.transform.position) <= 20f) { //hero go in the area //start catching if (!isCatching) { Debug.Log(this.gameObject + " is catching"); isCatching = true; } //moves direct to the hero addAction.addDirectMovement(this.gameObject); } else { if (isCatching) { Debug.Log(this.gameObject + " stops catching"); //hero has moved out of the area //stop catching gameStatusOp.heroEscapeAndScore(); isCatching = false; } //then moves randomly addAction.addRandomMovement(this.gameObject, false); } }
//检测进入自己区域的hero void checkNearByHero() { if (gameStatusOp.getHeroStandOnArea() == ownIndex) //只有当走进自己的区域 { if (!isCatching) { isCatching = true; addAction.addDirectMovement(this.gameObject); } } else { if (isCatching) //刚才为捕捉状态,但此时hero已经走出所属区域 { gameStatusOp.heroEscapeAndScore(); isCatching = false; addAction.addRandomMovement(this.gameObject, false); } } }