- Home /
Check marks in my dropdowns and disappearing UI elements...
Hello all!
You'll have to forgive me if this is a noob question, but I'm building a small test program to work on stuff with the UI and I'm having a couple of issues that I can't seem to resolve.
The first issue is that in my dropdown boxes, it appears like the check mark is appearing in the background of each item in the viewport. Here's what it looks like:
I've tried looking through all the parts and pieces of the dropdown, but I can't see where the check mark image might be getting added to the background of the list item. Plus, I haven't altered anything with the drop down. I just added some list items and attached a script to it. So if anybody could give me some advice on how to fix this, I'd be incredibly grateful.
The second problem I'm having has to do with my UI elements. I'm using this dropdown to alter the resolution of the window. But when I switch the resolution, the UI elements go wonky. Here's what I mean. When I start up the program everything looks fine. The UI elements get drawn where they're supposed to. But when I switch the resolution, it's like the UI elements don't get redrawn to account for the new resolution. Or if they do, they're being redrawn incorrectly, like this:
The larger the chance in resolution, the bigger problem gets (ie, jumping from 640x480 to 1024x600 causes the UI elements to completely move offscreen).
Right now, the script I'm using to alter the resolution (and thus the window size) is really simple:
using UnityEngine;
using System;
using System.Collections;
public class Script_horizontalResolutionDropDown : MonoBehaviour {
// Change the horizontal resolution
public void horizontalResolutionChange(int resolutionOption) {
if (resolutionOption == 0) {
Debug.Log("The resolution is 640x480!");
// Change the resolution
Screen.SetResolution(640, 480, false);
// Update the camera
Camera.main.orthographicSize = 240;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 1) {
Debug.Log("The resolution is 720x480!");
// Update the camera
Camera.main.orthographicSize = 240;
// Change the resolution
Screen.SetResolution(720, 480, false);
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 2) {
Debug.Log("The resolution is 800x480!");
// Change the resolution
Screen.SetResolution(800, 480, false);
// Update the camera
Camera.main.orthographicSize = 240;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 3) {
Debug.Log("The resolution is 854x480!");
// Change the resolution
Screen.SetResolution(854, 480, false);
// Update the camera
Camera.main.orthographicSize = 240;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 4) {
Debug.Log("The resolution is 960x540!");
// Change the resolution
Screen.SetResolution(960, 540, false);
// Update the camera
Camera.main.orthographicSize = 270;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 5) {
Debug.Log("The resolution is 800x600!");
// Change the resolution
Screen.SetResolution(800, 600, false);
// Update the camera
Camera.main.orthographicSize = 300;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 6) {
Debug.Log("The resolution is 1024x600!");
// Change the resolution
Screen.SetResolution(1024, 600, false);
// Update the camera
Camera.main.orthographicSize = 300;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 7) {
Debug.Log("The resolution is 960x640!");
// Change the resolution
Screen.SetResolution(960, 640, false);
// Update the camera
Camera.main.orthographicSize = 320;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 8) {
Debug.Log("The resolution is 1136x640!");
// Change the resolution
Screen.SetResolution(1136, 640, false);
// Update the camera
Camera.main.orthographicSize = 320;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 9) {
Debug.Log("The resolution is 1280x720!");
// Change the resolution
Screen.SetResolution(1280, 720, false);
// Update the camera
Camera.main.orthographicSize = 360;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 10) {
Debug.Log("The resolution is 1024x768!");
// Update the camera
Camera.main.orthographicSize = 384;
// Change the resolution
Screen.SetResolution(1024, 768, false);
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 11) {
Debug.Log("The resolution is 1280x768!");
// Change the resolution
Screen.SetResolution(1280, 768, false);
// Update the camera
Camera.main.orthographicSize = 384;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 12) {
Debug.Log("The resolution is 1280x800!");
// Change the resolution
Screen.SetResolution(1280,800, false);
// Update the camera
Camera.main.orthographicSize = 400;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 13) {
Debug.Log("The resolution is 1152x864!");
// Change the resolution
Screen.SetResolution(1152, 864, false);
// Update the camera
Camera.main.orthographicSize = 432;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 14) {
Debug.Log("The resolution is 1280x960!");
// Change the resolution
Screen.SetResolution(1280, 960, false);
// Update the camera
Camera.main.orthographicSize = 480;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else if (resolutionOption == 15) {
Debug.Log("The resolution is 1280x1024!");
// Change the resolution
Screen.SetResolution(1280, 1024, false);
// Update the camera
Camera.main.orthographicSize = 512;
// Update the canvases
Canvas.ForceUpdateCanvases();
} else {
Debug.Log("THIS RESOLUTION CHOICE IS IMPOSSIBLE!");
}
}
}
I tried the ForceUpdateCanvases to see if that would do anything, but it didn't make any difference. My Canvas is set to "Screen Space - Overlay" and my Canvas Scaler is set to "Constant Pixel Size." Also, I've got my two panels anchored to the Top-Right corner without any stretching. So, I'm kind of stumped. If anybody could point me in the right direction as to what I need to do to solve this problem, that'd be great.
Thanks In Advance!
As far as the resolution goes try reading this Dreamora seems to have the correct formula for setting the orthosize according to screen resolution
http://forum.unity3d.com/threads/orthographic-screen-size.113641/
I have the exact same issue with the checkmarks in my dropdown problem, did you find any fix yet?
-v3
Your answer
Follow this Question
Related Questions
Native Picker Wheel - iOS UI 0 Answers
Recieve an event when Dropdown is closed? 1 Answer
Dropdown not working with Oculus 3 Answers
Ui scaling 1 Answer
List to dropdown 0 Answers