Editor is bugged?

so im back from zero in unity but i had everything setup to work … one day i was working fine but the other day i get 15 errors when declaring a variable inside the update function
errors like variable type needed … } needed … ; needed
my code was right and its not even that complicated i just wrote 4 statements
anyone have a solution ??Preformatted text

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

public class PlayerMov : MonoBehaviour
    private Rigidbody2D rb;
    // Start is called before the first frame update
    void Start()
        rb = this.GetComponent<Rigidbody2D>();

    // Update is called once per frame
    void Update()
        private float speed n=1;
        rb.velocity = new Vector2(1, 0);


Welcome to our community.

Your code looks fine to me except for one little detail: the private access modifier in the Update method. Have you tried to remove it?

Well i can but i remember being able to make local variable instead of making them global … i mean i dont need to declare all variables as a class variable but i guess thats my only solution …

When you declare a variable within a code block, the variable is always local meaning within the scope of the code block only.

Did removing the private keyword solve the problem?

yes thank you :smiley:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.