Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Unity Canvas Change resolution

Discussion in 'UGUI & TextMesh Pro' started by PapayaLimon, Feb 15, 2023.

  1. PapayaLimon


    Aug 22, 2018
    Hi, I'm using this code to make an object appeared in any part inside a Collider2D, but the problem is that i cannot make it responsive, because if I added CanvasScaler then appears as too small, and object get out of the Collider. Is there a way it can resize with canvas size without making so small? Any idea on Canvas Configuration?

    Code (CSharp):
    1. public BoxCollider2D gridArea;
    2. private void RandomizePosition()
    3.     {
    4.         Bounds bounds = this.gridArea.bounds;
    5.         float x = Random.Range(bounds.min.x, bounds.max.x);
    6.         float y = Random.Range(bounds.min.y, bounds.max.y);
    7.         this.transform.position = new Vector3(Mathf.Round(x), Mathf.Round(y), 0.0f);
    8.             }
    9.     private void Start()
    10.     {
    11.         RandomizePosition();
    12.     }
    13.     void ChangePosition()
    14.     {
    15.         RandomizePosition();
    16.     }
    17. }

    If I added Canvas Scaler, and Add Scale with Screen size, it only works if i do it in bigger than 2056x1440 but not working in 16x9. And if i change Canvas properties to Constant Pixel Size it works but not responsive, any idea? The issue is the Box Collider is changing size all the time and I need that it stays the same all time :(