Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

[TUTORIAL] How to make Snake

Discussion in 'Project Tiny' started by sniffle63, Jan 27, 2019.

  1. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    I made a video on how to make snake with project tiny, if anyone would be so kinda as to give me feed back on how i could of done the code better, it would be greatly appreciated.
     
  2. SorneBachse

    SorneBachse

    Joined:
    Dec 27, 2012
    Posts:
    62
    Hey, just saw your tutorial, and I have some questions.

    This might be me who's new to ECS, but isn't it kind of against core principles for all the systems to reference and interact with each other the way you do ? To me, this seems very object oriented and a bit spaghetti, but I might be wrong.
     
    e199 likes this.
  3. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    This is my first project with unity Tiny, i cant give you a for sure answer because im sure im doing some things wrong. But from what i saw in the Project unity workshop, this seems how it would be approached? Not sure, hopefully someone smarter can tune in and say

    A better title for the video, is how to get snake working in unity tiny lol

    one thing i feel im doing wrong is using a foreach to find single objects. Im actually looking into how to do that better now. But the documents says getting an entity by its name is slow, and it seems it cant get children on entitys using the childs name. Atleast when i tried it it didnt work. But idk, im still learning unity tiny. Hopefully they quality will increase as i make more videos with it

    Iv come to the conclusion that doing this may be the best way to get single entitys and re use them

    Code (CSharp):
    1. export class ScoreSystem extends ut.ComponentSystem {
    2.         static scoreEntity: ut.Entity = null;
    3.         OnUpdate(): void {
    4.  
    5.             if (game.ScoreSystem.scoreEntity == null) {
    6.                 let textEntity = this.world.forEach([ut.Entity, ut.Text.Text2DRenderer, game.ScoreTag], (entity, text, tag) => {
    7.                     game.ScoreSystem.scoreEntity = new ut.Entity(entity.index, entity.version);
    8.                 });
    9.             } else {
    10.                 let text = this.world.getComponentData(game.ScoreSystem.scoreEntity, ut.Text.Text2DRenderer);
    11.                 text.text = "10";
    12.                 this.world.setComponentData(game.ScoreSystem.scoreEntity, text);
    13.             }
    14.            
    15.         }
    16.     }
     
    Last edited: Jan 29, 2019
  4. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Iv made a follow up video improving the code and adding in Ui and a game over system.