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

Feedback Help please scripting beginner

Discussion in 'Scripting' started by Bizarrestile, Apr 20, 2020.

  1. Bizarrestile

    Bizarrestile

    Joined:
    Apr 19, 2020
    Posts:
    5
    I’m trying to script a list of game objects, cards. I want to have a button show the top card. I only know a little so far, so I SetActive(true) and set the rest of the cards in the list false. Then I have another button appear when the card displays(SetActive (True) like a back button that I want to Remove the top card.
    question will the list update with a new [0] top card?
    Will this even work?
    What is a better way to do this as a beginner...any help would be appreciated.



    Code (CSharp):
    1.  
    2. Public List <GameOject> deckAcards=
    3. new List <GameObject>();
    4.  
    5. Public void OnClick ()
    6. {
    7. If (GameObject == deckAcards [0]);
    8. deckAcards[0].SetActive(true);
    9. Else
    10. deckAcards[1].SetActive(false);
    11. deckAcards[2].SetActive(false);
    12. deckAcards[3].SetActive(false);
    13. deckAcards[4].SetActive(false);
    14. Etc...
    15. }
    16. Public void OnDoneclick()
    17. {
    18. deckAcards[0].SetActive(false);
    19. List.Remove(deckAcards[0]);
    20.  
    21. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Best way is to start with the Unity Learn link at the top of this page. You want to get the syntax down (what you typed above is not at all compile-able code) and code syntax in a vacuum is just incredibly boring to start with.

    Therefore, since we want to be entertained and educated, it's always best to start with some Unity tutorials and then move onto a good Youtube tutorial guy who takes his time, supplies the code, explains everything, and then you can really start to wrap your head around it.

    Best of all, when you're done you can take code out of the tutorial example you made and use it to build upon!
     
    Bizarrestile likes this.
  3. Bizarrestile

    Bizarrestile

    Joined:
    Apr 19, 2020
    Posts:
    5
    thank you I have been watching videos (brackeys, unity.learn) for the past week I’m slowly understanding but I’m seeing how confusing coding can be.
    So I should just scrap all that ...
     
  4. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    130
    Learning the syntax is not the hard part.
    You have to get the mindset of a coder. You have to learn to develop a concept of your logic in your head before you write it down.

    The syntax is your pen.
    You can write with a pencil (javascript), with a noble fountain pen (C#), with a dried out marker (C++) or with F***ing fingerpaint (python).
    The only thing that matters is what you write down. It will be the same for every pen you use.

    But this doesn't come overnight. I started learning (c++ tho, not c#) about 6-7 years ago and am now able to maintain giant hobby projects on my own. Like, one c++ project is 20k lines long and my biggest unity game about 12k lines.

    But how did i start? Copying code from youtube videos over and over again because i could not rebuild it myself.
    At one point, a few weeks later, i actually managed to build this very code myself and this is the point from which things will change.
    The point where you understand the syntax and can implement your own ideas!
    I think brackeys is an awesome learning source!

    F*** boring programming books. Have not read a single one! F*** expensive online courses, did not attend a single one. Programming is not boring! Program what you WANT to. Not some dumbass hello world thingy. Make a game, doesn't matter if its bad.

    Actually, feel free to ask me if you don't know how to approach a certain issue
     
    Last edited: Apr 20, 2020