- Home /
 
               Question by 
               suraz24 · Sep 21, 2015 at 09:32 AM · 
                if-statementscondition  
              
 
              Multiple conditions being called????
Hi all,
I am trying to make a pirate game where players can collect several items. I am using random function to randomize the outcome. However, whenever I collect one item three different conditions are triggered. I have attached the code. Any help???
using UnityEngine; using System.Collections;
public class PickUpActivate : MonoBehaviour {
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () 
 {
 
 }
 public void PickUpChest()
 {
     Outcome ();
 }
 public void Outcome()
 {
     int outnum = Random.Range (1, 5);
     if(outnum == 1 || outnum == 2 || outnum ==4)
     {
         OutcomePositive();
         print("Positive");
     }
     else if(outnum == 3 || outnum == 5)
     {
         OutcomeNegative();
         print("negative");
     }
 }
 
 void OutcomePositive()
 {
     int outeff = Random.Range (1, 4);
     switch (outeff) 
     {
     case 1: OutcomeEffect("Orange"); print ("In positive orange"); break;
     case 2: OutcomeEffect("Banana");print ("In positive banana"); break;
     case 3: OutcomeEffect("Apple"); print ("In positive apple");break;
     case 4: OutcomeEffect("PineApple");print ("In positive pineapple"); break;
     }
 }
 
 void OutcomeNegative()
 {
     int outeff = Random.Range (1, 4);
     switch (outeff) 
     {
     case 1: OutcomeEffect("Lemon"); break;
     case 2: OutcomeEffect("Grapefruit"); break;
     case 3: OutcomeEffect("Lime"); break;
     case 4: OutcomeEffect("Pomegranate"); break;
     }
 }
 
 void OutcomeEffect(string effect)
 {
     if(effect== "Orange")
     {
         //Application.LoadLevel(1);
         //other.GetComponent<HealthBar>().UpdateHealthBar(-0.2f);
         print ("orange");
         
     }
     
     else if(effect== "Banana")
     {
         print ("banana");
         //Application.LoadLevel(1);
     }
     
     
     else if(effect== "PineApple")
     {
         print ("pineapple");
         //Application.LoadLevel(1);
     
     }
     
     else if(effect== "Apple")
     {
         print ("apple");
         
         //Application.LoadLevel(1);
     
     }
     
     else if(effect== "Lemon")
     {
         print ("lemon");
         //Application.LoadLevel(1);
     }
     
     else if(effect== "Grapefruit")
     {
         print ("grapefruit");
         //Application.LoadLevel(1);
     }
     
     else if(effect== "Lime")
     {
         print ("lime");
         //Application.LoadLevel(1);
     }
     
     else if(effect== "Pomegranate")
     {
         print ("pomegranate");
         //Application.LoadLevel(1);
     
     }
 }
}
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                