Home > Mobile >  Why does Unity found a problem but VSCode found none?
Why does Unity found a problem but VSCode found none?

Time:03-01

How do I fix this? Unity tells me I have error CS 1513 & 1022 at lines 7 & 18

Screenshot of Unity Editor in safe mode, displaying errors CS 1513 & 1022

This is exactly the code from the script that is causing all this

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

public class Camera1 : MonoBehaviour
{
    void Start() {
        private Vector3 NewPos = new Vector3(0, 0, 0);
    }

    // Update is called once per frame
    void Update()
    {
        NewPos = GameObject.Find("Thing").transform.position;
        NewPos.z  ;
        transform.position = NewPos;
    }
}

I tried fixing it according to what the errors mean, but it just gave me even more error messages.

Plus, VSCode found zero problems with missing { / }, how come?

CodePudding user response:

Your newpos vector is private, so you cant change it in another method. Try defining the vector at the top before all your methods but dont give it a value, then change the value in the start and update methods as you like. Remember that if you want to change the value in another script you need to set it as public

  • Related