GoalKeeerAnimations.directions GetRandomTiradaSinAtajar(Vector2 pos) { GoalKeeerAnimations.directions diferentDir = directions [Random.Range(0, directions.Length - 1)]; if (diferentDir != dir) { return(diferentDir); } else { return(GetRandomTiradaSinAtajar(pos)); } }
void OnGoalKeeperThrow(Vector2 pos, bool goal) { if (pos.y < -14) { ballPosition = ballPos.UP; } else if (pos.y < -7) { ballPosition = ballPos.MIDDLE; } else { ballPosition = ballPos.DOWN; } //print ("____" + pos + " ballPosition: " + ballPosition); if (pos.x > 16 || pos.x < -16 ) { SeQuedaParadoYMira(pos.x); return; } this.moveTo = initialPosition; float centerX = 4f; if (pos.x > 0 && pos.x < centerX) { if (pos.y < -20) { dir = GoalKeeerAnimations.directions.CENTER_TOP_LEFT; } else { dir = GoalKeeerAnimations.directions.MUEVE_IZQ; } } else if (pos.x < 0 && pos.x > -centerX) { if (pos.y < -20) { dir = GoalKeeerAnimations.directions.CENTER_TOP_RIGHT; } else { dir = GoalKeeerAnimations.directions.MUEVE_DER; } } else if (ballPosition == ballPos.UP && pos.x > centerX) { dir = GoalKeeerAnimations.directions.LEFT_TOP; } else if (ballPosition == ballPos.UP && pos.x < -centerX) { dir = GoalKeeerAnimations.directions.RIGHT_TOP; } else if (ballPosition == ballPos.DOWN && pos.x > centerX) { dir = GoalKeeerAnimations.directions.LEFT_BOTTOM; } else if (ballPosition == ballPos.DOWN && pos.x < -centerX) { dir = GoalKeeerAnimations.directions.RIGHT_BOTTOM; } else if (ballPosition == ballPos.MIDDLE && pos.x > centerX) { dir = GoalKeeerAnimations.directions.LEFT_MID; } else if (ballPosition == ballPos.MIDDLE && pos.x < -centerX) { dir = GoalKeeerAnimations.directions.RIGHT_MID; } //Si ataja: if (!goal) { moveTo.x = pos.x * 1.1f; } // no antaja: else { dir = GetRandomTiradaSinAtajar(pos); if (dir == GoalKeeerAnimations.directions.LEFT_BOTTOM || dir == GoalKeeerAnimations.directions.LEFT_MID || dir == GoalKeeerAnimations.directions.LEFT_TOP) { moveTo.x = Random.Range(7, 10); } else { moveTo.x = -Random.Range(7, 10); } } anim.JumpTo(dir, false); this.state = states.MOVEING; Invoke("Reset", 0.5f); }