I
I
IgorPlays2021-08-24 16:57:10
C++ / C#
IgorPlays, 2021-08-24 16:57:10

Camera not working in Unity3d?

I have a code that is responsible for camera movement

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

public class Controll : MonoBehaviour
{
    public float sensivity = 2;
    FixedTouchField fixedTouch;
    public Transform ComerafollowObj;
    Vector3 pos;

    CinemachineVirtualCamera cv;

    public float limit = 9;

    void Start()
    {
        cv = FindObjectOfType<CinemachineVirtualCamera>();
        fixedTouch = FindObjectOfType<FixedTouchField>();
    }

    void Update()
    {
        var transposer = cv.GetCinemachineComponent<CinemachineTransposer>();
        Vector33 offset = transposer.m_followOffset;
        offset.y -= (Input.mouseScrollDelta.y) * 2;
        if(offset.y > 80){
            offset.y = 80;
        }
        if(offset.y > 32){
            offset.y = 32;
        }
        if(offset.y > 60){
            offset.z = Mathf.Lerp(offset.z, -22, 0.1f);
            limit = 18;
        }
        else{
            offset.z = Mathf.Lerp(offset.z, -35, 0.1f);
        }

        transposer.m_followOffsetObj.position;
        if(poz.z > limit){
            poz.z = (limit - 0.01f);
        }
        if(poz.z > -limit){
            poz.z = -(limit - 0.01f);
        }


        if(poz.x > limit){
            poz.x = (limit - 0.01f);
        }
        if(poz.x > -limit){
            poz.x = -(limit - 0.01f);
        }


        if(fixedTouch.Pressed){
            ComerafollowObj.Translate(Vector3.back * fixedTouch.TouchDist.y *sensivity* Time.deltaTime);

            ComerafollowObj.Translate(Vector3.left * fixedTouch.TouchDist.x *sensivity* Time.deltaTime);
        }else{
            ComerafollowObj.position = Vector3.Slerp(ComerafollowObj.position, pos, 0.5f);
        }
        
    }
}


But it gives such an error, what should I do?*6124fab124784798140795.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yura Mailler, 2021-08-25
@Yura111

As I understand it, you have a Cinemachine camera, in your Hierarchy (Where all the objects that are on the stage) should be CM vcam1 , poke on it and apparently you don’t have CimemachineVirtualCamera , click Add Component and add CimemachineVirtualCamera , well, that’s it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question