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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

showing hint particle fx

Discussion in 'Scripting' started by Deleted User, Mar 9, 2018.

  1. Deleted User

    Deleted User

    Guest

    so in this function ,i need when user run this function , around current button a circle of particles get showed as game hint. how should i show that? i have already that particle effect created , but how to say to unity that now that user selected this function, show that effect on current button?
    Code (CSharp):
    1.     public void findCurrentPicture()
    2.     {
    3.         if (!CounterDownDone)
    4.             return;
    5.      
    6.         buttons [currentIndex].Select ();
    7.         if (gameScores < 30 )
    8.         {
    9.             gameScores = gameScores;
    10.             GameBuyCoinsPanel.SetActive (true);
    11.             Time.timeScale = 0.0f;
    12.         }
    13.  
    14.         if (gameScores >= 30 )
    15.         {
    16.             gameScores -= 30;
    17.         }
    18.         gamescorestext.text = ((int)gameScores).ToString ();
    19.     }
    just there in line buttons [currentIndex].Select ();
    i need to say around this current button show particle effect. thanks.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    If your particle effect is already in place, (that is, on the button, but turned off). Just turn it on. If you're using it elsewhere then you'll need to move it into place and then turn it on.
     
  3. Deleted User

    Deleted User

    Guest

    if i move particle system inside canvas , it will be disappeared . after that i tried making it off. but even , it will not be on.
    not showing in canvas , nor working with that function. any idea what is wrong ?
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    You'll need your canvas to be screen space -camera and you'll have to set the layer of your particle to be higher than your canvas.
     
  5. Deleted User

    Deleted User

    Guest

    should it be a child of button ? or it is not important? after hierarchy thing, now imagine that is in correct place. But in code after above function runs, how will it make particle system on? this is my question.
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Objects in your hierarchy are GameObjects, so you can turn them on just like any gameobject. If you have play on awake checked, the particle will start playing when turned on. You can have it laid out however, but the particles themselves have an order in layer on them that you want to set higher than the canvas.
     
    Deleted User likes this.
  7. Deleted User

    Deleted User

    Guest

    its working now with layering , i changed order in layer in renderer part in inspector. it is turned off now. also that is child of a ui button.
    but still when i click on that ui button , particle system will not be shown. whats wrong? code is available above.
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    How are you turning on the particle? When you click on the button, you need to get the particle. Either you need to have a reference on the script and then set the particle active, or you need to get the particle gameobject when the button is clicked on (different ways of doing this) and then turn it on.
     
  9. Deleted User

    Deleted User

    Guest

    particle system will now be on / off by clicking on UI button, and actually what i need to do is : in scene i have 5 buttons.
    i need if i clicked on find it button, then it will show particle system on current active button (from 5) . relating particle system to the place of specific button is question here. like hidden objects games , where you click on hint button and it will show you required item, any help? above is function i use with find it or hint button,
     
  10. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I was pm'd by the OP.. I asked him if he followed the suggestions from the thread and so on first, and gave him a small example script here:
    Code (csharp):
    1. public class Test14 : MonoBehaviour
    2. {
    3.     public Button[] test;
    4.     public ParticleSystem ps;
    5.  
    6.     void SetOnButton(Button b)
    7.     {
    8.         ps.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
    9.         ps.transform.SetParent(b.transform, false);
    10.         ps.transform.localPosition = Vector3.zero;
    11.         ps.Play();
    12.     }
    13.     void Start()
    14.     {
    15.         SetOnButton(test[0]);
    16.     }
    17.     void Update()
    18.     {
    19.         if (Input.GetMouseButtonDown(0))
    20.         {
    21.             SetOnButton(test[1]);
    22.         }
    23.     }
    24.     // Buttons' OnClick events calls this method.
    25.     public void ButtonClicked()
    26.     {
    27.         ps.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
    28.     }
    29. }
    Obviously, it's not 100% what he asked for but a close facsimile :)
    Order in layer for the PS was set to 1, Screen space camera for the canvas.. can't remember if I'm forgetting any notes I passed along, but pretty tired.. Just leaving this here in case the OP is stuck, and someone else is helping out. :)
     
    Deleted User likes this.
  11. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    From the looks of that code, you're passing in a button to FindCurrentButton. So each button in most likely it's onclick, you need to be calling that but passing in the button that you are clicking on so the particle moves to that button.
     
  12. Deleted User

    Deleted User

    Guest

    inside inspector, at onclick only i can drag and drop one button from five. how can i extend it to more buttons?
     
  13. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Your onclicks should reference the method and have the slot for the button. You just add the button that you want it to target there. It's not limited to one button.

    When you setup the onclick for each button, each one has it's own place for a button to be dragged and dropped.
     
    Deleted User likes this.
  14. Deleted User

    Deleted User

    Guest

    wait please. i have 2 types of button.

    type1 is only one button which is called find it. only this button can create particle and send it towards 5 button in type2.

    type2 are five buttons. they can be clicked and they dont produce particle.

    when type1 button is clicked , i need from its position on game scene , particles move towards other 5 buttons, but one after other. i would thanks you and i need your answer.
     
  15. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Then you'll need to set your buttons up in an array or list and when you click, it moves to the next button.
     
    Deleted User likes this.
  16. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Sometimes, I can't tell where you're stuck... sorry.

    I was imagining that you have a current button index (the one that should be found or hinted at).

    So, when you click the 'show hint' button, you simply call the method I wrote, using the current index (and of course, a button array)
    Code (csharp):
    1. int currentIndex = 0;
    2. public Button [] buttons;
    3. public void ShowHint() {
    4.     ShowOnButton(buttons[currentIndex]); // <- method from my code posted above.
    5.   }
    Something like that.
     
    Deleted User likes this.
  17. Deleted User

    Deleted User

    Guest

    @methos5k , this structure is already done in my code, i mean i have an array of buttons with indexnumber as int
    it means now by click on each correct needed button , next button on array will be needed, but at the same time i want to have another option in my game too. this option is show current button from array with particle effects.

    at the moment i have created particles in game scene, i created a button for hint. this button will show user needed button with showing particles there. i need just this functionality. thanks all.
     
  18. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I knew that's what you were after, and that's what my post was about.

    There is either a communication issue and/or a code issue, sorry.

    My most recent post was showing that clicking on a button to show a hint (particle on the button) could be achieved through that method. That post also refers to a method that I wrote in a previous post, as the comment mentions*.

    Do you see how it ties together?
     
  19. Deleted User

    Deleted User

    Guest

    would you please write your codes completly one more time all together, because i am mixed up. sorry.
     
  20. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, if you take my example from several posts back, and copy in the most recent one (remove 1 of the button arrays), then you'll basically have everything I've talked about.

    When you want to click a main button, call the method that stops the particle system.
    When you want to show a hint, call the method from the most recent post.

    That's all there is to it. :)
     
    Deleted User likes this.
  21. Deleted User

    Deleted User

    Guest

    you know what? i am not good at organising things hehehehhe, please bring them all together lol.
    i have no idea which code from where , maybe i copy these comments to script,:)
     
  22. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Post #10 and #17. c'mon man lol. Just copy them. Oh boy...:)
     
    Deleted User likes this.
  23. Deleted User

    Deleted User

    Guest

    so , i try that. and say you here the result. thanks.
     
  24. Deleted User

    Deleted User

    Guest

    besides your code , also in my script , i have already used button arrays and currentindex int .
    are those all similar together?
     
    Last edited by a moderator: Mar 11, 2018
  25. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You can just erase Start() and Update from mine -- which were just for an example.. completely unrelated to the core of what you'd use. :)
     
    Deleted User likes this.
  26. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Oh, and of course use just 1 button array and current index.. Obviously I had to add that to make the example work ;)
     
    Deleted User likes this.
  27. Deleted User

    Deleted User

    Guest

    it is working all fine now with this code for my game example. now particles will be created at the position of each button. i need they move from hint button towards needed button. i have primarily located particles near hint button. how can they move towards each button though?thanks.

    Code (CSharp):
    1.     public void RequiredItems(int imageNum)
    2.     {
    3.         if (!CounterDownDone)
    4.             return;
    5.      
    6.         if(ShowTotalItems < 1)
    7.         {
    8.             GameWinPanel.SetActive (true);
    9.         }
    10.  
    11.         if(imageNum == currentIndex)
    12.         {
    13.             gameScores += 10;
    14.             PlayerPrefs.SetInt ("Gamescores",gameScores);
    15.             gamescorestext.text = ((int)gameScores).ToString ();
    16.             ShowTotalItems--;
    17.             Showtotalitems.text = ((int)ShowTotalItems).ToString ();
    18.  
    19.  
    20.             buttons[currentIndex].GetComponent<Image>().enabled = false;
    21.  
    22.             if (currentIndex < questions.Length -1)
    23.             {
    24.                 question.text = questions[currentIndex + 1];
    25.                 currentIndex++;
    26.             }
    27.             else
    28.                 question.text = "You've found all";
    29.         }
    30.  
    31.         else if(gameScores > 10)
    32.         {
    33.             gameScores -= 10;
    34.             PlayerPrefs.SetInt ("Gamescores",gameScores);
    35.             gamescorestext.text = ((int)gameScores).ToString ();
    36.         }
    37.  
    38.         helpfx.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
    39.  
    40.     }
    41.     void ShowOnButton(Button b)
    42.     {
    43.         helpfx.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
    44.         helpfx.transform.SetParent(b.transform, false);
    45.         helpfx.transform.localPosition = Vector3.zero;
    46.         helpfx.Play();
    47.     }
    48.  
    49.     public void findCurrentPicture(Button b)
    50.     {
    51.         if (!CounterDownDone)
    52.             return;
    53.  
    54.         ShowOnButton(buttons[currentIndex]);
    55.  
    56.  
    57.         if (gameScores < 30 )
    58.         {
    59.             gameScores = gameScores;
    60.             GameBuyCoinsPanel.SetActive (true);
    61.             Time.timeScale = 0.0f;
    62.         }
    63.         if (gameScores >= 30 )
    64.         {
    65.             gameScores -= 30;
    66.         }
    67.         gamescorestext.text = ((int)gameScores).ToString ();
    68.     }
     
    Last edited by a moderator: Mar 11, 2018
  28. Deleted User

    Deleted User

    Guest

    how can i move particle systems? i created a public Transform . but it does not work.
     
    Last edited by a moderator: Mar 11, 2018