Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to show/hide a sprite use typescript?

Discussion in 'Project Tiny' started by chbin, Jan 23, 2019.

  1. chbin

    chbin

    Joined:
    Dec 27, 2012
    Posts:
    2
    How to show/hide a sprite use typescript?
     
  2. FutureWang

    FutureWang

    Joined:
    May 24, 2018
    Posts:
    22
    you can add the component ut.Disabled to hide,and remove the component ut.Disabled to show;
    code:
    let ent = this.world.createEntity();
    this.world.addComponent(ent,ut.Disabled);

    hope to help you .
     
  3. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    129
    Might be nice to have a utility method for such functions:

    Code (CSharp):
    1. /** Sets the active state of an entity. */
    2. static SetActive(world: ut.World, entity: ut.Entity, active: boolean): void {
    3.     if (active) {
    4.         if (world.hasComponent(entity, ut.Disabled)) {
    5.             world.removeComponent(entity, ut.Disabled);
    6.         }
    7.     } else {
    8.         if (!world.hasComponent(entity, ut.Disabled)) {
    9.             world.addComponent(entity, ut.Disabled);
    10.         }
    11.     }
    12. }