Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[HELP]How to get the canvas/screen resolution?

Discussion in 'Project Tiny' started by WellC, Dec 20, 2018.

  1. WellC

    WellC

    Joined:
    Mar 2, 2015
    Posts:
    48
    I want to get the canvas/screen resolution, but I don't know how to get it.I want to use resolution to maintain the aspect ratio.
     
    caiobg2 likes this.
  2. ullatussimo

    ullatussimo

    Unity Technologies

    Joined:
    Jun 16, 2015
    Posts:
    108
    Hi @WellC,

    You can use the following piece of code to get the size of the browser frame / device display:
    Code (JavaScript):
    1.     const displayInfo = this.world.getConfigData(ut.Core2D.DisplayInfo);
    2.  
    3.     const frameWidth = displayInfo.frameWidth;
    4.     const frameHeight = displayInfo.frameHeight;
    5.  
    6.     const screenHeight = displayInfo.screenHeight;
    7.     const screenWidth = displayInfo.screenWidth;
    I would recommend using the frameWidth & frameHeight.

    Hope this helps!

    Cheers,
    Simo
     
    caiobg2 likes this.
  3. WellC

    WellC

    Joined:
    Mar 2, 2015
    Posts:
    48
    Thank u ; And I have some question ,
    1.How to disable an entity(just like gameobject setactive(true/false),No Destory)?
    2.How to judge the end of tween execution? Or callback?
     
  4. SoerenBachNielsen

    SoerenBachNielsen

    Joined:
    Dec 27, 2012
    Posts:
    40
    You can disable an entity by adding the component ut.Disabled I think it's called.
     
  5. NSWell

    NSWell

    Joined:
    Jul 30, 2017
    Posts:
    33
    Thanks for your reply, but I donot know how to use this API for
     ut.Disabled
    because I have seen API-Doc and tried it in Unity.Do you have more information about the
    ut.Disabled
    API information?
     
  6. ER_Dolleman

    ER_Dolleman

    Joined:
    Dec 10, 2018
    Posts:
    19
    I think it's supossed to work like this:
    Code (JavaScript):
    1. this.world.addComponent(entity, ut.Disabled);
    However, the entity is still visible for me, and I had an error one time about the Hitbox2D component, so I'm not sure if this is the correct way to use it.

    Edit: Oh oops, I made a mistake in the code. It does make the entity invisible, but I do have an error if I do it on an entity with the Hitbox2D component

    Code (JavaScript):
    1. Assertion failed: man.hasComponent<HitBoxOverlapResults>(ce.e), at: C:/Users/Abdul/Documents/tiny/Runtime/modules/hitbox2d/src/HitBox2D.cpp,700,
     
    Last edited: Dec 21, 2018
  7. WellC

    WellC

    Joined:
    Mar 2, 2015
    Posts:
    48
    Thanks for yours reply, I think you can remove
    Hitbox2D
    component first.