// Return true si las condiciones para atacar al masterpillar son las adecuadas private bool atackMasterPillar() { //Master pillar no ha sido destruido if (masterPillarTransform != null) { //Distancia correcta para atacar al pilar maestro if (checkDistance(atackDistancePillar, masterPillarTransform.position)) { if (!stateAtackPillar.isStateActive()) { currentState.stopState(); currentState = stateAtackPillar; stateAtackPillar.startState(); } } else { //Tengo que ir a por el pilar if (!stateGoToPillar.isStateActive()) { currentState.stopState(); currentState = stateGoToPillar; stateGoToPillar.startState(); } } return(true); } return(false); }
//Estado de defender el pilar private bool defendPillar() { //En caso de que el master pillar este siendo atacado if (masterPillar != null && masterPillar.isBeingAtacked()) { //Hay que asignarle un enemigo al que atacar if (enemy == null) { //Se solicita un enemigo enemy = masterPillar.getEnemy(); //Si no hay disponibles, no se ataca if (enemy == null) { return(false); } } //Activa el modo de alerta this.setAlertMode(); //Distancia me permite atacar al enemigo if (checkDistance(atackDistance, enemy.transform.position)) { if (!atackEnemy.isStateActive()) { atackEnemy.setEnemyPosition(enemy); currentState.stopState(); currentState = atackEnemy; atackEnemy.startState(); } } else { //En caso contrario voy a por el if (!goToEnemy.isStateActive()) { goToEnemy.setDestination(enemy); goToEnemy.setCharacterSpeed(4.0f); currentState.stopState(); currentState = goToEnemy; goToEnemy.startState(); } } return(true); } return(false); }
/* * Si las condiciones para atacar al character son las adecuadas devuelve true */ private bool atackCharacter() { //Se comprueba la distancia respecto al personaje principal if (checkDistance(rayCastDistance, mainCharacterTransform.position)) { //Actualizo el rayo para que la direccion sea la correcta originRay = transform.position; originRay.y += 1; directionMainCharacter = 1.1f * (mainCharacterTransform.position - transform.position); //Debug.DrawRay (originRay,directionMainCharacter); //Lanzo el rayo isHit = Physics.Raycast(originRay, directionMainCharacter, out rayHit, rangeOfView); //Ha dado al personaje principal if (isHit && (rayHit.transform.tag == "Player")) { //La distancia contra el personaje me permite atacarlo if (rayHit.distance < atackDistanceCharacter) { if (!stateAtackCharacter.isStateActive()) { currentState.stopState(); currentState = stateAtackCharacter; stateAtackCharacter.startState(); } } else { //Estoy viendo al peronaje a una distancia adecuada para ir tras el pero no para atacarlo if (!stateGoToCharacter.isStateActive()) { currentState.stopState(); currentState = stateGoToCharacter; stateGoToCharacter.startState(); } } return(true); } } return(false); }