Posts by AGDev

    Be aware of Singletons! They're actually an anti pattern and shouldn't be used. There are better ways how you can solve this problem. My two recommendations would be:


    Either use a DI-Framework or use ScriptableObjects ( Scriptable Objects ).


    With both then will have the benefits of:

    • Testability
    • No direct dependency to the real implementation
    • No directly link to a certain GameObject
    • Reuseability

    You have a point. There are endless discussions about using singletons is good or bad.


    I get the anti pattern definition, but I also think that using them in a moderated way can be benefitial.


    If you're working solo and on a small project, using a singleton shouldn't cause you any trouble. It's different if you're working on large projects and as a part of a team.


    I'm actually working on a small project for mobile and I'm using just 2 singleton scripts, one for game management stuff and the other one for player management stats. That's it.

    They are really useful and I'm taking care of not messing with them :D


    I think it's great to know when to use it and if it's worth it.

    Hey Taron! welcome to the community!


    It's great that you are already working in a team if they're all as motivated as you.


    Not my case, I have to wear all the hats myself for now. But it's nice also, since I'm learning a lot and I like it all.


    I see you around!

    IMHO it's not so important the player prefab's persistence but its stats. The stats are the ones you'll need to maintain from scene to scene.


    So in that case I would recommend to use one empty gameobject with the singleton script attached to it. In that script you'll have player stats, whatever other values you need to maintain during the game, setters and getters, audio manager, etc ... and the DontDestroyOnLoad.


    This is an example explained by Jonathan on his courses



    You create an empty GameObject and attach the GameManager script into it. Then you can call those methods from other scripts to initialize or modify values.


    For example:


    Code
    1. GameManager.Instance.Score = 0


    You can add to the singleton whatever you want ... live points, score points, booleans to check, bullets amounts ... everything you need to use in your game on every scene.


    I hope it helps :)


    EDIT: Now that I'm seeing, this script doesn't contains the DontDestroyOnLoad, but it should work. There are other ways to create a Singleton, this is one of them.

    Here you have other way to do the same



    It works like a charm also.

    Yeahh! I finally got it working!. Your answer helped me a lot to find the final solution. This is the right code to use:



    I don't need to assign the button, just find it using the GameObject.Find ... it works like a charm! :)


    Thanks a lot for the help!

    Hey everyone.


    I'm running in some kind of mental blackout and can't make this to work as I want.


    Here is the thing ... I have my first scene in which I'm loading a lot of gameobjects and stuff, and the one that I'm interested in is the MobileSingleStickControl, a prefab taken from the Standard Assets (the same Jon used in the Dungeon Escape course).

    That GameObject contains 3 childrens ... 2 buttons and the MobileJoystick. The first button is the one I'm using to fire a weapon, that's working perfectly fine.


    Now, after level 1 is finished it goes to the next scene in which you can see some kind of shop where you can buy some stuff with game points or advertisement. You can buy there a PowerUp attack which you'll be able to fire using the 2nd button of the joystick. Then you proceed to a new scene for playing level 2.

    So what I want is to change the 2nd button image after you bought the power up.

    What I did is to add this code to the Singleton script that will remain throughout the game.



    In the thorns variable I assign the png sprite I want after the power up is bought.

    In the originalImage I assign the 2nd button of the joystick


    The boolean thornsRain variable is being changed from another script (I have getters and setters for that), so at the Start of the 2nd level scene, the EnableThornsRain() method is being called to change images .... BUT, the problem is that the originalImage I've assigned (with the 2nd button) disappears when I change scenes, so I'm missing that reference.


    I'm thinking of reaching the Image component of the 2nd button through code, but I'm not completely sure about finding components in children and I'm a bit lost here.


    Any help would be most appreciated :)

    Now that you mention this, yes ... I'm having that delay in my project as well, but I did nothing about it yet. It's a slight delay, not as long as 1 entire second, but it becomes noticeable if you play enough times.


    Definitively this is something that we need to solve.


    There are some answers here that may come in handy. I'll read it better tomorrow, it's late here and I'm about to go to bed :)


    https://answers.unity.com/ques…0916/fix-sound-delay.html

    You definitely posted the right question. I would like to know more on this topic too.

    If thats true and trademarks legislation is per country, that's just crazy, i can't believe it..

    This is an interesting document about Trademarks in the US. It mentions that trademarks are territorial, but an owner can apply to register a trademark in all countries that are part of the Madrid Protocol with a single registration form.


    https://www.stopfakes.gov/arti…mark-in-a-Foreign-Country


    Not sure if it worth the pain for an Indie "company" though

    Thanks for your answers.


    Yes, it's not a big deal at the moment, but it was something that kept me thinking, mostly about the music stuff.


    Trademarks legislation is per country, so I would have to register everything on each country I'd like to keep my rights. It doesn't make any sense when I'm publishing a game in the Google Play Store and/or the Apple Store and it's becoming available to a large number of countries.


    I guess Indie developers like us won't do that at all

    Hi everyone.


    Perhaps some of you have experience to teach me about this. I was reading out there that there is no need to do any copyright of a game you make. You are automatically the owner of the game. But is there any legal protection? So what about the name you give to your game and to your own new Company? Do you have to register that somewhere?


    What about the music you compose for the game?


    I'm doing all of that, and although I'm far from publishing it, there'll be a moment that I'll need to take care of all that.

    That's an interesting point, the legal agreement. I'm not sure how it should be handled either. Maybe at first it should be a matter of trust among each part.


    I'm working solo for the time being at my own pace and by my own rules. That makes those things easier for me although I'm not so good when I'm wearing the "graphical artist" hat :P

    Hi Corysia! Thanks for your response.


    Yes, as a matter of fact I have my variables with [SerializeField] and I could see that the conditions were perfectly met. Prior picking up the 2nd weapon everything worked fantastic.


    For some weird reason, the problem got solved after I treated the bulletAmount == 0 condition as a new separated IF

    Nevermind ..... I solved it by separating the last IF.


    I'll leave the code just in case anyone finds a similar case, but it's strange ... I think it should work anyway, but I don't know. It works now :)