Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Change text in component

Discussion in 'Project Tiny' started by TheFordeD, Feb 5, 2019.

  1. TheFordeD

    TheFordeD

    Joined:
    Jul 9, 2018
    Posts:
    30
    I have TS code:
    Code (JavaScript):
    1. this.getComponent(world, gameInterface.Labels.Credits, [ut.Text.Text2DRenderer], function (Text) {
    2.                 Text.text = Data.credits;
    3.             });
    this method:
    Code (JavaScript):
    1. static getComponent(world: ut.World, entity: ut.Entity, comp: any, callback: (obj: any) => any): void {
    2.             world.usingComponentData(entity, comp, callback);
    3.         }
    Why text not a changed after method?
     
  2. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    118
    Tiny doesn't use GetComponent() they have getComponentData() method


    1) Get componentData from Entity
    2) Change Data
    3) Set Data onto Entity
     
  3. TheFordeD

    TheFordeD

    Joined:
    Jul 9, 2018
    Posts:
    30
    Result:
    upload_2019-2-5_17-32-58.png

    Code:
    Code (JavaScript):
    1. static getComponent(world: ut.World, entity: ut.Entity, comp: any, callback: (obj: any) => any): void {
    2.             world.usingComponentData(entity, comp, callback);
    3.             var Component = world.getComponentData(entity, comp);
    4.             world.setComponentData(entity, Component);
    5.         }
     
  4. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    118
    Ignoring the callback part, and the static class. . . try this logic

    Code (JavaScript):
    1.    
    2.             let textRenderer:ut.Text.Text2DRenderer = this.world.getComponentData(entity, ut.Text.Text2DRenderer);
    3.             textRenderer.text = "I'm Loving it!";
    4.             this.world.setComponentData(entity, textRenderer);
     
    TheFordeD likes this.
  5. TheFordeD

    TheFordeD

    Joined:
    Jul 9, 2018
    Posts:
    30
    Thanks. I do it another


    Code (JavaScript):
    1. static getComponent<T>(world: ut.World, entity: ut.Entity, comp: any, callback: (obj: T) => T): void {
    2.             let Component:T = world.getComponentData(entity, comp);
    3.             Component = callback(Component);
    4.             world.setComponentData(entity, Component);
    5.         }
    6.  
    7. ...
    8.  
    9.  
    10. this.getComponent<ut.Text.Text2DRenderer>(world, gameInterface.Labels.Credits, ut.Text.Text2DRenderer, function (Text) {
    11.                 Text.text = Data.credits.toString();
    12.                 return Text;
    13.             });
     
    vincismurf likes this.