//to get player movement and set its parent //call movement start method //find foot object public virtual void Start( ) { if (bInit) { movement = GetComponent <PlayerMovement> ( ); attack = GetComponent <PlayerAttack> ( ); health = GetComponent <PlayerHealth> ( ); paintball = GetComponent <PlayerPaintball> ( ); skill = GetComponent <ISkill> ( ); animator = GetComponent <Animator> ( ); UI = GameObject.Find(numPlayer + "UI").GetComponent <PlayerUI> ( ); skill.Parent = this; skill.SetActive(true); UI.Parent = this; health.Parent = this; attack.Parent = this; movement.Parent = this; paintball.Parent = this; UI.Start( ); attack.Start( ); movement.Start( ); health.Start( ); paintball.Start( ); //footObject = transform.Find ("Foot").gameObject; } }
// Update is called once per frame /// <summary> /// Update this instance. /// this handles taking the inputs and sending the correct repsone to the attack script /// this is done by button presses to determine the correct response that are depicted by different screens /// </summary> void Update() { GameObject[] enemyObjects = GameObject.FindGameObjectsWithTag("Enemy2"); if (enemyObjects.Length != 0) { if ((battle.timeToAttack > 99) && (counter != 1)) { counter = 1; } if ((battle.timeToAttack < 99) && (counter == 1)) { counter = 0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; flag = 0; flagCheck = false; } if (counter == 1) { if ((Input.GetKeyUp("joystick button 0")) && (flag != 1) && (!flagCheck)) { flag = 1; flagCheck = true; } if ((Input.GetKeyUp("joystick button 1")) && (flag != 2) && (!flagCheck)) { flag = 2; flagCheck = true; } if ((Input.GetKeyUp("joystick button 2")) && (flag != 3) && (!flagCheck)) { flag = 3; flagCheck = true; } if ((Input.GetKeyUp("joystick button 3")) && (flag != 4) && (!flagCheck)) { flag = 4; if (buttonPressedCheck == 0) { } else { buttonPressedCheck = 0; } } if (flag == 1) { //Attack(); GameObject[] game = GameObject.FindGameObjectsWithTag("Enemy2"); if (Input.GetKeyUp("joystick button 10")) { EnemyNumber--; if (EnemyNumber < 0) { EnemyNumber = 0; } } if (Input.GetKeyUp("joystick button 11")) { EnemyNumber++; if (EnemyNumber > game.Length - 1) { EnemyNumber = game.Length - 1; } } for (int cnt = 0; cnt < optionsToSelect.Length; cnt++) { if ((attackDisplay + cnt) > stored._attack.Length) { attackDisplay--; } if ((attackDisplay + cnt) < stored._attack.Length) { optionsToSelect[cnt] = stored._attack[cnt + attackDisplay]; } if (Input.GetKeyUp("joystick button 8")) { attackDisplay--; if (attackDisplay < 0) { attackDisplay = 0; } } if (Input.GetKeyUp("joystick button 9")) { attackDisplay++; } if (cnt == optionsToSelect.Length - 1) { optionsToSelect[3] = "Back"; } if (Input.GetKeyUp("joystick button 3")) { flag = 0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; attackDisplay = 0; flagCheck = false; } if ((Input.GetKeyUp("joystick button 0")) && (secondCheck == true)) { waitingPeriod += 0.1f; if (waitingPeriod > 0.6f) { if (optionsToSelect[0] == "Attack") { attacking = new PlayerAttack(); attackType = "Attack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.AttackEnemy(); secondCheck = false; waitingPeriod = 0; } if (optionsToSelect[0] == "FireAttack") { attacking = new PlayerAttack(); attackType = "FireAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.FireAttackEnemy(); secondCheck = false; waitingPeriod = 0; } } } if /*(Input.GetKeyUp("joystick button 2"))*/ ((Input.GetKeyUp("joystick button 1")) && (secondCheck)) { waitingPeriod += 0.1f; if (waitingPeriod > 0.6f) { if (optionsToSelect[1] == "FireAttack") { attacking = new PlayerAttack(); attackType = "FireAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.FireAttackEnemy(); secondCheck = false; waitingPeriod = 0; } if (optionsToSelect[1] == "IceAttack") { attacking = new PlayerAttack(); attackType = "IceAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.IceAttackEnemy(); secondCheck = false; waitingPeriod = 0; } } } if (Input.GetKeyUp("joystick button 2")) /*(Input.GetKeyUp("joystick button 3")){*/ { waitingPeriod += 0.1f; if (waitingPeriod > 0.6f) { if (optionsToSelect[2] == "IceAttack") { attacking = new PlayerAttack(); attackType = "IceAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.IceAttackEnemy(); secondCheck = false; waitingPeriod = 0; } if (optionsToSelect[2] == "LightningAttack") { attacking = new PlayerAttack(); attackType = "LightningAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.LightningAttackEnemy(); secondCheck = false; waitingPeriod = 0; } } } if (Input.GetKeyUp("joystick button 3")) /*(Input.GetKeyUp("joystick button 1")){*/ { } } if ((flag == 1) && (((Input.GetKeyUp("joystick button 0"))) || ((Input.GetKeyUp("joystick button 1"))) || ((Input.GetKeyUp("joystick button 2"))) ) && (secondCheck == false)) { secondCheck = true; } } if (flag == 2) { //Magic(); for (int cnt = 0; cnt < optionsToSelect.Length; cnt++) { if ((attackDisplay + cnt) > stored._mana.Length) { attackDisplay--; } if ((attackDisplay + cnt) < stored._mana.Length) { optionsToSelect[cnt] = stored._mana[cnt + attackDisplay]; } if (Input.GetKeyUp("joystick button 8")) { attackDisplay--; if (attackDisplay < 0) { attackDisplay = 0; } } if (Input.GetKeyUp("joystick button 9")) { attackDisplay++; } if (cnt == optionsToSelect.Length - 1) { optionsToSelect[3] = "Back"; } } GameObject[] game = GameObject.FindGameObjectsWithTag("Enemy2"); if (Input.GetKeyUp("joystick button 10")) { EnemyNumber--; if (EnemyNumber < 0) { EnemyNumber = 0; } } if (Input.GetKeyUp("joystick button 11")) { EnemyNumber++; if (EnemyNumber > game.Length - 1) { EnemyNumber = game.Length - 1; } } if (Input.GetKeyUp("joystick button 3")) /*(Input.GetKeyUp("joystick button 1")){*/ { flag = 0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; attackDisplay = 0; flagCheck = false; } if ((Input.GetKeyUp("joystick button 0")) && (secondCheck == true)) { waitingPeriod += 0.3f; Debug.Log(waitingPeriod); if (waitingPeriod > 0.7f) { if (optionsToSelect[0] == "Fire") { attackingWithMagic = new MagicAttack(); attackType = optionsToSelect[0]; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; // flag =0; waitingPeriod = 0; } if (optionsToSelect[0] == "Water") { attackingWithMagic = new MagicAttack(); attackType = optionsToSelect[0]; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod = 0; } } } if /*(Input.GetKeyUp("joystick button 2"))*/ ((Input.GetKeyUp("joystick button 1")) && (secondCheck)) { waitingPeriod += 0.3f; Debug.Log(waitingPeriod); if (waitingPeriod > 0.7f) { if (optionsToSelect[1] == "Wind") { attackingWithMagic = new MagicAttack(); attackType = "Wind"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod = 0; } if (optionsToSelect[1] == "Ice") { attackingWithMagic = new MagicAttack(); attackType = "Ice"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.IceAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod = 0; } } } if (Input.GetKeyUp("joystick button 2")) /*(Input.GetKeyUp("joystick button 3")){*/ { waitingPeriod += 0.3f; Debug.Log(waitingPeriod); if (waitingPeriod > 0.7f) { if (optionsToSelect[2] == "Water") { attackingWithMagic = new MagicAttack(); attackType = "Water"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod = 0; } if (optionsToSelect[2] == "Lightning") { attackingWithMagic = new MagicAttack(); attackType = "Lightning"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.LightningAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod = 0; } } } if (Input.GetKeyUp("joystick button 3")) /*(Input.GetKeyUp("joystick button 1")){*/ { } if ((flag == 2) && (((Input.GetKeyUp("joystick button 0"))) || ((Input.GetKeyUp("joystick button 1"))) || ((Input.GetKeyUp("joystick button 2"))) ) && (secondCheck == false)) { secondCheck = true; waitingPeriod += 0.1f; } } if (flag == 3) { // Items(); for (int cnt = 0; cnt < optionsToSelect.Length; cnt++) { /*if((attackDisplay+cnt)>stored.items.Length){ * attackDisplay--; * }*/ if (((attackDisplay + cnt) < stored.items.Length) && (cnt < stored.items.Length)) { optionsToSelect[cnt] = stored.items[cnt + attackDisplay]; } else { optionsToSelect[cnt] = ""; } if (Input.GetKeyUp("joystick button 8")) { attackDisplay--; if (attackDisplay < 0) { attackDisplay = 0; } } if (Input.GetKeyUp("joystick button 9")) { attackDisplay++; } if (cnt == optionsToSelect.Length - 1) { optionsToSelect[3] = "Back"; } } if (Input.GetKeyUp("joystick button 0")) { } if /*(Input.GetKeyUp("joystick button 2"))*/ (Input.GetKeyUp("joystick button 1")) { } if (Input.GetKeyUp("joystick button 2")) /*(Input.GetKeyUp("joystick button 3"))*/ { } if (Input.GetKeyUp("joystick button 3")) /*(Input.GetKeyUp("joystick button 1")){*/ { flag = 0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; attackDisplay = 0; flagCheck = false; } } if (flag == 4) { Run(); } } } }
// Update is called once per frame /// <summary> /// Update this instance. /// this handles taking the inputs and sending the correct repsone to the attack script /// this is done by button presses to determine the correct response that are depicted by different screens /// </summary> void Update() { GameObject[] enemyObjects = GameObject.FindGameObjectsWithTag("Enemy2"); if(enemyObjects.Length!=0){ if((battle.timeToAttack>99)&&(counter!=1)){ counter =1; } if((battle.timeToAttack<99)&&(counter==1)){ counter =0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; flag=0; flagCheck=false; } if(counter==1){ if((Input.GetKeyUp("joystick button 0"))&&(flag!=1)&&(!flagCheck)){ flag =1; flagCheck=true; } if((Input.GetKeyUp("joystick button 1"))&&(flag!=2)&&(!flagCheck)){ flag=2; flagCheck=true; } if((Input.GetKeyUp("joystick button 2"))&&(flag!=3)&&(!flagCheck)){ flag=3; flagCheck=true; } if((Input.GetKeyUp("joystick button 3"))&&(flag!=4)&&(!flagCheck)){ flag =4; if(buttonPressedCheck==0){ } else{ buttonPressedCheck=0; } } if(flag==1){ //Attack(); GameObject[] game = GameObject.FindGameObjectsWithTag("Enemy2"); if(Input.GetKeyUp("joystick button 10")){ EnemyNumber--; if(EnemyNumber < 0) EnemyNumber =0; } if(Input.GetKeyUp("joystick button 11")){ EnemyNumber++; if(EnemyNumber > game.Length-1){ EnemyNumber =game.Length-1; } } for(int cnt =0; cnt < optionsToSelect.Length; cnt ++){ if((attackDisplay+cnt)>stored._attack.Length){ attackDisplay--; } if((attackDisplay+cnt)<stored._attack.Length){ optionsToSelect[cnt] = stored._attack[cnt+attackDisplay]; } if(Input.GetKeyUp("joystick button 8")){ attackDisplay--; if(attackDisplay < 0) attackDisplay =0; } if(Input.GetKeyUp("joystick button 9")){ attackDisplay++; } if(cnt == optionsToSelect.Length-1){ optionsToSelect[3] = "Back"; } if(Input.GetKeyUp("joystick button 3")){ flag =0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; attackDisplay=0; flagCheck = false; } if((Input.GetKeyUp("joystick button 0"))&&(secondCheck==true)){ waitingPeriod+=0.1f; if(waitingPeriod>0.6f){ if(optionsToSelect[0]=="Attack"){ attacking = new PlayerAttack(); attackType = "Attack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.AttackEnemy(); secondCheck = false; waitingPeriod=0; } if(optionsToSelect[0] =="FireAttack"){ attacking = new PlayerAttack(); attackType = "FireAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.FireAttackEnemy(); secondCheck = false; waitingPeriod=0; } } } if/*(Input.GetKeyUp("joystick button 2"))*/ ((Input.GetKeyUp("joystick button 1"))&&(secondCheck)){ waitingPeriod+=0.1f; if(waitingPeriod>0.6f){ if(optionsToSelect[1]=="FireAttack"){ attacking = new PlayerAttack(); attackType = "FireAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.FireAttackEnemy(); secondCheck = false; waitingPeriod=0; } if(optionsToSelect[1] =="IceAttack"){ attacking = new PlayerAttack(); attackType = "IceAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.IceAttackEnemy(); secondCheck = false; waitingPeriod=0; } } } if(Input.GetKeyUp("joystick button 2"))/*(Input.GetKeyUp("joystick button 3")){*/ { waitingPeriod+=0.1f; if(waitingPeriod>0.6f){ if(optionsToSelect[2]=="IceAttack"){ attacking = new PlayerAttack(); attackType = "IceAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.IceAttackEnemy(); secondCheck = false; waitingPeriod=0; } if(optionsToSelect[2] =="LightningAttack"){ attacking = new PlayerAttack(); attackType = "LightningAttack"; attacking.Start(); attacking.retrieveEnemies(EnemyNumber); attacking.LightningAttackEnemy(); secondCheck = false; waitingPeriod=0; } } } if(Input.GetKeyUp("joystick button 3"))/*(Input.GetKeyUp("joystick button 1")){*/{ } } if((flag==1)&& (((Input.GetKeyUp("joystick button 0")))|| ((Input.GetKeyUp("joystick button 1")))|| ((Input.GetKeyUp("joystick button 2"))) )&&(secondCheck==false)){ secondCheck=true; } } if(flag==2){ //Magic(); for(int cnt =0; cnt < optionsToSelect.Length; cnt ++){ if((attackDisplay+cnt)>stored._mana.Length){ attackDisplay--; } if((attackDisplay+cnt)<stored._mana.Length){ optionsToSelect[cnt] = stored._mana[cnt+attackDisplay]; } if(Input.GetKeyUp("joystick button 8")){ attackDisplay--; if(attackDisplay < 0) attackDisplay =0; } if(Input.GetKeyUp("joystick button 9")){ attackDisplay++; } if(cnt == optionsToSelect.Length-1){ optionsToSelect[3] = "Back"; } } GameObject[] game = GameObject.FindGameObjectsWithTag("Enemy2"); if(Input.GetKeyUp("joystick button 10")){ EnemyNumber--; if(EnemyNumber < 0) EnemyNumber =0; } if(Input.GetKeyUp("joystick button 11")){ EnemyNumber++; if(EnemyNumber > game.Length-1){ EnemyNumber =game.Length-1; } } if(Input.GetKeyUp("joystick button 3")){/*(Input.GetKeyUp("joystick button 1")){*/ flag =0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; attackDisplay=0; flagCheck=false; } if((Input.GetKeyUp("joystick button 0"))&&(secondCheck==true)){ waitingPeriod+=0.3f; Debug.Log(waitingPeriod); if(waitingPeriod>0.7f){ if(optionsToSelect[0]=="Fire"){ attackingWithMagic = new MagicAttack(); attackType = optionsToSelect[0]; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; // flag =0; waitingPeriod=0; } if(optionsToSelect[0] =="Water"){ attackingWithMagic = new MagicAttack(); attackType = optionsToSelect[0]; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod=0; } } } if/*(Input.GetKeyUp("joystick button 2"))*/ ((Input.GetKeyUp("joystick button 1"))&&(secondCheck)){ waitingPeriod+=0.3f; Debug.Log(waitingPeriod); if(waitingPeriod>0.7f){ if(optionsToSelect[1] =="Wind"){ attackingWithMagic = new MagicAttack(); attackType = "Wind"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod=0; } if(optionsToSelect[1] =="Ice"){ attackingWithMagic = new MagicAttack(); attackType = "Ice"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.IceAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod=0; } } } if(Input.GetKeyUp("joystick button 2"))/*(Input.GetKeyUp("joystick button 3")){*/ { waitingPeriod+=0.3f; Debug.Log(waitingPeriod); if(waitingPeriod>0.7f){ if(optionsToSelect[2] =="Water"){ attackingWithMagic = new MagicAttack(); attackType = "Water"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.FireAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod=0; } if(optionsToSelect[2] =="Lightning"){ attackingWithMagic = new MagicAttack(); attackType = "Lightning"; attackingWithMagic.Start(); attackingWithMagic.retrieveEnemies(EnemyNumber); attackingWithMagic.LightningAttackEnemy(); secondCheck = false; //flag =0; waitingPeriod=0; } } } if(Input.GetKeyUp("joystick button 3"))/*(Input.GetKeyUp("joystick button 1")){*/{ } if((flag==2)&& (((Input.GetKeyUp("joystick button 0")))|| ((Input.GetKeyUp("joystick button 1")))|| ((Input.GetKeyUp("joystick button 2"))) )&&(secondCheck==false)){ secondCheck=true; waitingPeriod+=0.1f; } } if(flag==3){ // Items(); for(int cnt =0; cnt < optionsToSelect.Length; cnt ++){ /*if((attackDisplay+cnt)>stored.items.Length){ attackDisplay--; }*/ if(((attackDisplay+cnt)<stored.items.Length) &&(cnt < stored.items.Length)){ optionsToSelect[cnt] = stored.items[cnt+attackDisplay]; }else{ optionsToSelect[cnt] = ""; } if(Input.GetKeyUp("joystick button 8")){ attackDisplay--; if(attackDisplay < 0) attackDisplay =0; } if(Input.GetKeyUp("joystick button 9")){ attackDisplay++; } if(cnt == optionsToSelect.Length-1){ optionsToSelect[3] = "Back"; } } if(Input.GetKeyUp("joystick button 0")){ } if/*(Input.GetKeyUp("joystick button 2"))*/ (Input.GetKeyUp("joystick button 1")){ } if(Input.GetKeyUp("joystick button 2"))/*(Input.GetKeyUp("joystick button 3"))*/ { } if(Input.GetKeyUp("joystick button 3")){/*(Input.GetKeyUp("joystick button 1")){*/ flag =0; optionsToSelect[0] = "Attack"; optionsToSelect[1] = "Magic"; optionsToSelect[2] = "Items"; optionsToSelect[3] = "Run"; attackDisplay=0; flagCheck=false; } } if(flag==4){ Run(); } } } }