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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

particles problem

Discussion in 'Scripting' started by Dino1997, Feb 27, 2011.

  1. Dino1997

    Dino1997

    Joined:
    Nov 8, 2010
    Posts:
    30
    hello , i made this script and when i press button it should made 1 flame at cube,but when i press button it creates a lot of flames and that slow my computer,and it looks bad....can anyone help me ,thanks

    Code (csharp):
    1.  
    2. if(Village_Looted) {
    3.                var looted = Instantiate(Village_Fire,
    4.                              GameObject.Find("FirePoint").transform.position,
    5.                                           Quaternion.identity);
    6.     }
    here is completed code
    Code (csharp):
    1.  
    2. var Village_Looted:boolean = false;                        //village looted da ili ne
    3. var Village_Menu:boolean = false;                          //
    4. var Show_Peasants_Inventory:boolean = false;       //torba seljaka
    5. var Show_Hostile_Action_Menu:boolean = false;      //neprijateljski akcija
    6. var Village_Name:String;                                       //ime sela
    7. var Village_Description:String;                                // opis sela
    8. var Populace:int;                                                //popularnost
    9. var Background_Texture:Texture2D;                       //background texture
    10. var Player:Transform;                                          //Igrach
    11. var Village_Position:Transform;                              //pozicija sela
    12. var Village_Fire:Transform;
    13.  
    14. function OnMouseDown() {
    15.     Village_Menu = true;
    16. }
    17.  
    18. function OnGUI() {
    19.     if(Village_Menu) {
    20.         GUI.Label(new Rect(20, 20, Screen.width, 1000), Background_Texture);
    21.        
    22.         if(GUI.Button(new Rect(20, 20, 40, 40), "Go To The Village Center.")) {
    23.             Player.position = Village_Position.position;
    24.             Village_Menu = false;
    25.         }
    26.        
    27.         if(GUI.Button(new Rect(40, 40, 40, 40), "Buy Supplies From Peasants.")) {
    28.             Show_Peasants_Inventory = true;
    29.             Village_Menu = false;
    30.         }
    31.        
    32.         if(GUI.Button(new Rect(60, 60, 40, 40), "Take A Hostile Action.")) {
    33.             Show_Hostile_Action_Menu = true;
    34.             Village_Menu = false;
    35.         }
    36.        
    37.         if(GUI.Button(new Rect(80, 80, 40, 40), "Leave...")) {
    38.             Village_Menu = false;
    39.         }
    40.     }
    41.     if(Village_Looted) {
    42.         var looted = Instantiate(Village_Fire,
    43.                                           GameObject.Find("FirePoint").transform.position,
    44.                                           Quaternion.identity);
    45.     }
    46.  
    47.    
    48.     if(Show_Hostile_Action_Menu)
    49.         if(GUI.Button(new Rect(20, 20, 40, 40), "Loot and Burn This Village")) {
    50.             Village_Looted = true;
    51.             Show_Hostile_Action_Menu = false;
    52.         }
    53. }
    54.  
     
  2. Dino1997

    Dino1997

    Joined:
    Nov 8, 2010
    Posts:
    30
    anyone?
     
  3. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    Sounds like you're instantiating inside function Update() so it instantiates a new particle system every frame as long as Village_Looted is true. You can use a boolean to stop this.

    Code (csharp):
    1. private var flames : boolean = false;
    2.  
    3. function Update ()
    4. {
    5.  
    6. if (Village_Looted  !flames)
    7. {
    8. MakeFlames();
    9. }
    10. }
    11.  
    12. function MakeFlames()
    13. {
    14. //your instantiation code
    15. flames = true;
    16. }
    I put it in a separate function in case you want to add a yield or other statement to turn flames false again. Don't know if this is the problem you're having, but sounds like it might be the case.