- Home /
Game Camera not scaling correctly when built.
Hello, as part of my game development college course i have to make a 2d game prototype, and i have encountered a few problems, but only 1 i need to fix urgently. The main problem is that when i build the game the menu works as desired, but upon clicking play and going to the game, the game camera is smaller and i can still see a bit of the menu on the right of my game, as shown in the picture. (http://i.imgur.com/z3Nc47E.png) i first took it off free aspect which helped it a bit but as you can see the problem is still pretty blatant and i'm out of ideas as to why its happening, both the menu and the camera for the game are the exact same size both image wise and camera scaling. the win/lose screens work perfectly it's just the game that shows this. any help would be appreciated greatly. thank you for your time.
Gotta know more. What system are you using to draw your menu? Unity 4.6+'s UI, legacy GUI, something else? Why do you continue to draw your menu when it's no longer needed? Show us some relevant code and describe your situation in much greater detail. Best,
Sorry man, im very new to this as this is first assignment where we have to basically learn it ourselves, my menu works as a separate scene that takes me to the game scene on button press using "Application.LoadLevel ("");", i am doing this using the uk system that was added in 4.6 though i'm on unity 5. below i will post a picture of each step and quote the relevant code used.
The $$anonymous$$enu (http://i.imgur.com/i0STULF.png) ->Click play -> The Game Opens (http://i.imgur.com/j2PLeU4.png)
the code used to navigate from menu to game:
*using UnityEngine; using System.Collections;
public class $$anonymous$$ain$$anonymous$$enu : $$anonymous$$onoBehaviour {
public Texture backgroundTexture;
public GUIStyle Random1;
public GUIStyle Random2;
public float guiPlacementY;
public float guiPlacementX;
public float guiPlacementY2;
public float guiPlacementX2;
void OnGUI(){
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture);
//PLAY
if (GUI.Button (new Rect(Screen.width * guiPlacementX, Screen.height * guiPlacementY, Screen.width * .5f, Screen.height * .2f),"", Random1)){
Application.LoadLevel ("ArrowDash");
}
//QUIT
if (GUI.Button (new Rect(Screen.width * guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .45f, Screen.height * .2f),"", Random2)){
Application.Quit();
}
}
}*
$$anonymous$$ost of that is to get button positions done well. As you can see here (http://i.imgur.com/ZN4t5FC.png) if i place the menu image i made behind the game camera/HUD they are the same size, so it seems as if the game scene is being re sized across the x axis to allow for that gap on the right that shows the menu behind it.
$$anonymous$$enu Camera Settings (http://i.imgur.com/NhFo5tP.png) Game Camera Settings (http://i.imgur.com/4EvXzOh.png)
if you need any more information please let me know i hope this covers the important parts as i'm at a loss as to what this is.
i don't know the policy on bumping threads on here, but my deadline is this Thursday so please if anyone has a suggestion i'm all ears :s
Answer by emayberry · Mar 17, 2015 at 06:13 PM
First of all, if you're using the new 4.6 UI components then you shouldn't need to deal with the OnGUI() method. If I were you, I would create a script with methods for navigating between scenes and attach it to a GameObject in your initial scene (don't forget to mark the gameobject as DontDestroyOnLoad or it'll disappear between scenes). I would then create the UI buttons using the inspector and use the OnClick functions to call methods on the controller. There are some good YouTube tutorials that I think suit your needs perfectly here:
Part 1 (Creating the menu) Part 2 (Changing scenes using OnClick)
Answer by captainkrisu · Mar 17, 2015 at 09:21 PM
You don't really need any scripting with the new UI system.
Have you tried changing Ui Scale Mode in Canvas, Canvas Scaler (Script).
And if you want to check how your menu scaling works, click "Maximize on play" in game view, or drag the game view out of unity editor, and scretch it as you want.
Your answer
Follow this Question
Related Questions
Camera too zoomed in in built game 1 Answer
Depth Fade Problem on distance in VR 0 Answers
Game preview incorrect! 0 Answers
Cinemachine weird lines of color when moving? 1 Answer
Distribute terrain in zones 3 Answers