Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

if statement problem

Discussion in 'Scripting' started by phedon, Feb 2, 2015.

  1. phedon

    phedon

    Joined:
    Dec 7, 2013
    Posts:
    10
    I am making a project for the university in unity and i dont know how to define something that i want the script to make.I have made three object lists and i want when the player eats one object from the first list and one from the second list,to choose a random object from the third list and instantiate an other object in the chosen object position.The problem is if the player eats four objects from the first list and three objects from the second list to produce only three instantiate objects and vice versa, and all this gone on untill the all objects of the third list have an instantiated object in their position.The objects in the third list are about 506.

    Thank you in advance,and i hope to find me a solution

    here is the script that i have made so far

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3.  
    4. public class GameLogikScript : MonoBehaviour {
    5.  
    6.     public GameObject Eye;
    7.  
    8.     public static int Score = 0;
    9.  
    10.     bool Simulation = false;
    11.  
    12.     static public List<GameObject> Eyes = new List<GameObject>();
    13.     static public List<GameObject> Flies = new List<GameObject>();
    14.     static public  List<GameObject> Surface = new List<GameObject>();
    15.  
    16.  
    17.     void Start ()
    18.     {
    19.         Eyes.AddRange(GameObject.FindGameObjectsWithTag ("EyesMolecules"));
    20.  
    21.  
    22.         }
    23.  
    24.    
    25.     void Update()
    26.     {
    27.  
    28.  
    29.  
    30.         Debug.Log (Eyes.Count);
    31.         Debug.Log (Flies.Count);
    32.         Debug.Log (Surface.Count);
    33.  
    34.         if (Flies.Count != 0 && Surface.Count != 0)
    35.         {
    36.             if (Flies.Count <= Surface.Count)
    37.             {
    38.  
    39.  
    40.                 int rnd = Random.Range (1, Eyes.Count);
    41.  
    42.                 Debug.Log("An Eye is looking you" + Eyes[rnd]);
    43.  
    44.                 Instantiate(Eye, Eyes[rnd].renderer.bounds.center, Eyes[rnd].transform.localRotation) ;
    45.                 Debug.Log ("Instatiate");
    46.                
    47.             }
    48.  
    49.                 }
    50.         }
    51.  
    52.  
    53.     void OnGUI()
    54.     {      
    55.         GUI.Label(new Rect(10, 10, 100, 20),Score.ToString());
    56.        
    57.     }
    58. }
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
    Are you asking us to help you cheat on your homework? ;)
     
  3. phedon

    phedon

    Joined:
    Dec 7, 2013
    Posts:
    10
    :)
    It is not a homework,it is a project that i choose to make with unity,for the multimedia class

    :p