Search Unity

Attaching Prefeb effect issue

Discussion in 'Prefabs' started by cecebeans85, Jan 10, 2020.

  1. cecebeans85


    Dec 19, 2019
    Hi all, I am very new here and I am not sure if I am posting in the correct place. But I am currently making a puzzle game and I built a prefab edge glow for when the piece locks into place the edges emit. I attached the prefab to Edge Particles and I typed C# so that it should only react once the puzzle piece connects to it's place. When I run it nothing happens once the piece locks into place. Please see the code below I used and the screenshot of where I attached the prefab.

    I hope someone can help. Let me know if you need further details. upload_2020-1-10_6-55-25.png upload_2020-1-10_6-56-34.png
  2. olejuer


    Dec 1, 2014

    my suggestion is to pause the game right after the piece locks. Then checkout the scene view and see if the edgeglow was actually spawned. Select it and try to find out why you don't see it. Maybe it is rotated wrong or really small or the particle effect does not start automatically.
    If you are unsure whether a piece of code is executed when you would expect, try to add a
    Debug.Log("some text");
    By the way, are there any errors in your console?

    Also, on an entirely different note, do you know enums? Try this:
    Code (CSharp):
    1. public enum PieceStatus {
    2.     Unlocked,
    3.     Locked
    4. }
    6. public PieceStatus pieceStatus = PieceStatus.Unlocked;
    this is better than using strings for status, because with strings it is easy to make a typo. Also, your initial pieceStatus of an empty string has an unclear meaning. With enums, the status must be one of the defined ones. If it is only a question of locked/unlocked, though, you should use a bool instead.

    Happy Unitying!