- Home /
 
 
               Question by 
               zak666 · Jan 16, 2016 at 05:49 AM · 
                scripting problem  
              
 
              Phrasing error: trying to make a shop with multiple conditions of ints for unlocking items. handle multiple if statements?
Hi guys somthing funny is going on trying to make a simple system here, if you have enough of X,Y,Z, you can unlock a fighter. "not sue how to handle multiple if statements" using UnityEngine; using System.Collections;
 public class SpacePortControll : MonoBehaviour {
 
 
     // Requiremeents Fighter 01.
     public int One_reacorce1required = 10;
     public int One_reacorce2required = 10;
     public int One_GoldRequired = 1000;
     public int RequiredLevel = 1;
 
 //--------------------------------------------------------------------------------------------------------------
 //Unlock Fighter.
     void PuchaseFighter01 (){
         // check required SG and reasorcess to unlock Fighter.
         if(Missioncontroll.Gold >= One_SpaceGoldRequired)
         if(Missioncontroll.reacorce1 >= One_reacorce1required)
         if(Missioncontroll.reacorce2 >= One_reacorce2required) 
         if(Missioncontroll.Level >= RequiredLevel)
         {
             //Unlock Fighter  also reduce the Users gold and reasorces by the amount spent in store.
             Missioncontroll.Fighter2 += +1;
             Missioncontroll.SpaceGold -= -One_SpaceGoldRequired;
             Missioncontroll.reacorce1 -= -One_reacorce1required;
             Missioncontroll.reacorce2 -= -One_reacorce2required;
             Missioncontroll.UpdateProfile();  // update profile automaticly. (run void updateprofile to update online profile after unlocking)
         }
     }
 //-------------------------
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by SterlingSoftworks · Jan 16, 2016 at 06:06 AM
You've got the right mind set but not quite! The logic is there, but the syntax isn't.
          if(Missioncontroll.Gold >= One_SpaceGoldRequired && Missioncontroll.reacorce1 >= One_reacorce1required && Missioncontroll.reacorce2 >= One_reacorce2required && Missioncontroll.Level >= RequiredLevel)
          {
              //Unlock Fighter  also reduce the Users gold and reasorces by the amount spent in store.
              Missioncontroll.Fighter2 += +1;
              Missioncontroll.SpaceGold -= -One_SpaceGoldRequired;
              Missioncontroll.reacorce1 -= -One_reacorce1required;
              Missioncontroll.reacorce2 -= -One_reacorce2required;
              Missioncontroll.UpdateProfile();  // update profile automaticly. (run void updateprofile to update online profile after unlocking)
          }
 
               From what it looks like from your code is that once all 4 conditions are met, you execute the "Unlock" fighter part. If so, that should work :)
Remember!!! OR operand is || AND operand is &&
So..
 //OR
 if(x == 2 || x == 1){
 print("x is equal to 2 or 1");
 }
 
 //AND
 if(x ==2 && y ==1){
 print("x is equal to 2 AND y is equal to 1");
 }
 
 
              Your answer