Ошибка CS0120: ссылка на объект требуется для нестатического c поля, метода или свойства CameraController.main. - PullRequest
0 голосов
/ 31 января 2020
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour {

    public float main;
    public Transform car;
    public float distance;
    public float height;
    public float rotationDamping;
    public float zoomRatio;
    public float defaultFOV;

    public float rotation_vector;

    void FixedUpdate()
    {
        Vector3 local_velocity = car.InverseTransformDirection(car.GetComponent<Rigidbody>().velocity);
        if (local_velocity.z <-0.5f)
        {
            rotation_vector = car.eulerAngles.y;

        }
        else
        {
            rotation_vector = car.eulerAngles.y;
        }

        float accelaration = car.GetComponent<Rigidbody>().velocity.magnitude;
        CameraController.main.fieldOfView = defaultFOV + accelaration * zoomRatio * Time.deltaTime;
    }

    void LateUpdate()
    {
        float wantedAngle = rotation_vector;

        float wantedHeight = car.position.y + height;
        float myAngle = transform.eulerAngles.y;
        float myHeight = transform.position.y;

        myAngle = Mathf.LerpAngle(myAngle, wantedAngle, rotationDamping * Time.deltaTime);
        myHeight = Mathf.LerpAngle(myHeight, wantedHeight, heightDamping * Time.deltaTime);

        quaternion currentRotation = Quaternion.Euler(0, myAngle, 0);

        transform.position = car.position;
        transform.position -= currentRotation * Vector3.forward * distance;

        Vector3 temp = transform.position;
        temp.y = myHeight;
        transform.position = temp;

        transform.LookAt(car);





    }

}

1 Ответ

0 голосов
/ 31 января 2020

Я не уверен, что это за язык. Это определенно не javascript несмотря на добавленный вами тег. Он выглядит как java, за исключением ключевых слов using, : и стиля.

Если предположить, что это язык, подобный Java, то ошибка говорит вам использовать this.main вместо CameraController.main. Вы можете сделать <className>.<property> только для полей c. Для не * stati c полей вам нужно использовать <objectName> вместо <classname>.

При этом в вашем коде есть другие ошибки; как сразу после, у вас есть main.fieldOfView несмотря на то, что main имеет тип float.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...