I
I
iGniteR112019-11-30 23:53:50
C++ / C#
iGniteR11, 2019-11-30 23:53:50

'Camera' does not contain a definition for 'main'?

'Camera' does not contain a definition for 'main'? What is the problem? tell me please

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

public class BG : MonoBehaviour
{
    
    void Start()
    {
        var height = Camera.main.ortographicSize * 2f;

        var width = height * Screen.width / Screen.height;
        if (gameObject.name == "Background")
        {
            transform.localScale = new Vector3(width, height, 0);
        }
    }

    
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
2
2CHEVSKII, 2019-12-01
@2chevskii

What is the problem?

The person who sits in front of the computer.
Can't you read? There is no such field in Camera as main.

F
freeExec, 2019-12-01
@freeExec

You need to assign a tag to the cameraMainCamera

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question