Search Unity

Changing Sprites using scripts

Discussion in '2D' started by Shady Cake, May 1, 2016.

  1. Shady Cake

    Shady Cake

    Joined:
    Aug 12, 2015
    Posts:
    2
    Hello! I am wanting to make a birds-eye view pixel-art game.

    I currently have two sprite sheets set up, and split and whatnot.
    groundSheet and characterSheet these are split up into
    ground_0_0_0 (A concrete floor)
    ground_1_0_0 (grass)
    character_0_0_0 (man idle animation frame 1)
    character_0_0_1 (man idle animation frame 2)
    character_0_1_0 (man run animation frame 1)
    character_0_1_1 (man run animation frame 2)
    character_1_0_0 (woman idle animation frame 1)
    character_1_0_1 (woman idle animation frame 2)
    character_1_1_0 (woman run animation frame 1)
    character_1_1_1 (woman run animation frame 2)

    The numbers after are a note as to:
    first number - the main set of sprite animations (eg man)
    second number - the animation set in use (eg run or idle)
    third number - the frame of said animation.
    (the ground has this as i plan to have animated grounds late on)

    Now, I wish to make a script for the character (and ground alike) that has an editable value that is view able in the unity editor, for example how things like the sprite renderer has sprite, colour etc. Which dictates what first number to use (see above) what second number and the delay for the animation of the third number. This will then tell the sprite renderer what pictures to load and how quickly to load them. I also wish for the script to scan for the file starting with for example character_0_0_ and then count how many files after it, so it knows what to do when animating. I would like this script to be checking for a change in one of the variables viewable in the unity editor to change and as soon as it does it checks everything it needs for an animtion.

    Something else could be done where there is only 1 box to edit in unity, which you put character_0_0_ or ground_1_0_ or something similar, and it checks everything that way (it also makes the script universal, and usable on the ground, character and walls (which I am adding later)).

    This may seem confusing, but it make sense for me and many of you will probably mention a much easier way to do animations and such, but please only say these if it does what I want above.

    For scripts and such my file layout:
    /Assets
    /scripts
    ground.cs
    character.cs
    /sprites
    characterSheet.png
    character_0_0_0
    character_0_0_1
    character_0_1_0
    character_0_1_1
    character_1_0_0
    character_1_0_1
    character_1_1_0
    character_1_1_1
    groundSheet.png
    ground_0_0_0
    ground_1_0_0

    ground.cs and character.cs are the scripts in which I want to made as explained above.
    In my object view thingy I have
    Main Camera
    ground
    character

    I am practically a newb to C# and JS I know bascially the grammar of C# (like where to use {} and put ; at the end of the lines). If you help me with this, i request that you explain the script, like use the // thing to simply explain what each command does, I know a few but not all of them. And I know someone is going to say it is really well documented in tutorial X and such, but most tutorials are not in unity 5 and while helping with the matter do not touch on it exactly.

    Thank you for your help, if there is anything about this question/request that you do not understand (It is pretty complex) I will explain.