- Home /
Question by
levan1 · Dec 14, 2014 at 01:19 PM ·
resolutionfixed
Cannot convert type `UnityEngine.Vector2' to `int'
My game default resolution is 800x500 in the webplayer. I want this resolution to be fixed, in case of changing resolution, the game load other scene. How can I do this?
error CS0030: Cannot convert type UnityEngine.Vector2' to
int'
using UnityEngine;
using System.Collections;
public class Resolution : MonoBehaviour {
Vector2 targetResolution;
void Start()
{
targetResolution = new Vector2(800, 500);
}
void Update ()
{
if(Screen.width != (int)targetResolution || Screen.height != (int)targetResolution)
{
Application.LoadLevel("MainMenu");
}
}
}
Comment
Best Answer
Answer by .Talon · Dec 14, 2014 at 01:25 PM
Since Vector2 contains two values, you can't simply convert it into one. But you can access these values (x and y coordinates).
void Update ()
{
if(Screen.width != (int)targetResolution.x || Screen.height != (int)targetResolution.y)
{
Application.LoadLevel("MainMenu");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613174021im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Keep sprites at fixed size 3 Answers
Standalone fullscreen-fixed size 0 Answers
Fixed to the screen GUI ? 1 Answer
Fixed position of GUI content (same for every resolution). 3 Answers
Clamping after forcing aspect ratio 0 Answers