error with my script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class screenadjuster : MonoBehaviour {

// Use this for initialization
void Start ()
{
float targetaspect = 16.0f / 9.0f;
float windowaspect = (float)Screen.width / (float)Screen.height;
float scaleheight = windowaspect / targetaspect;
Camera camera = GetComponent ();
}
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;

rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;

camera.rect = rect;
}
else 16.0f
}
float scalewidth = 1.0f / scaleheight;

Rect rect = camera.rect;

rect.width = scalewidth;

rect rect = camera.rect;

rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;

camera.rect = Rect;
}
It keeps saying that ‘if’ ‘else’ and ’ float’ are unexpected symbols. Can somebody tell me my mistake?

For starters, please use the code tags to help with readability.
It looks like you have an extra closing brace ( } ) in your Start method, which closes it off.

void Start () 
{
float targetaspect = 16.0f / 9.0f;
float windowaspect = (float)Screen.width / (float)Screen.height;
float scaleheight = windowaspect / targetaspect;
Camera camera = GetComponent<Camera> ();
} //Right here
if (scaleheight < 1.0f)
{
1 Like
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class screenadjuster : MonoBehaviour {

    // Use this for initialization
    void Start ()
    {
        float targetaspect = 16.0f / 9.0f;
        float windowaspect = (float)Screen.width / (float)Screen.height;
        float scaleheight = windowaspect / targetaspect;
        Camera camera = GetComponent<Camera> ();
   
        if (scaleheight < 1.0f) {
            Rect rect = camera.rect;

            rect.width = 1.0f;
            rect.height = scaleheight;
            rect.x = 0;
            rect.y = (1.0f - scaleheight) / 2.0f;

            camera.rect = rect;
        } else
            16.0f;
    }
        float scalewidth = 1.0f / scaleheight;

        Rect rect = camera.rect;

// all these down here
        rect.width = scalewidth;
        rect.height = 1.0f;
        rect.x = (1.0f - scalewidth) / 2.0f;
        rect.y = 0;

        camera.rect = Rect;
}

Thanks, that helped and sorry about that, I’m still a noob. But I have another problem, the code is telling me that the equal signs on the parts that I mentioned in the code are unexpected symbols, I have no idea what that means.

The } on line 26 is closing your start method.

1 Like

What are you expecting line 25 to do?