I found this in another question, but nobody there had the answers. I am making a 2d sidescroller platforming game with some of my friends, and this error appears. The previous answers said to make sure it is in the right project and that there are no errors in the project, and I have satisfied both of those solutions to no avail. Also, when i click on the script in unity and the inspector window pops up, it says “No MonoBehavior scripts in the file, or their names do not match the file name” even though the name of the script and the name of the class are the same. Here is my script code, if it is any help:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class parallax : MonoBehaviour
{
private float length;
private float startpos;
public float parallaxEffect;
public GameObject cam;
// Start is called before the first frame update
void Start()
{
startpos = transform.position.x;
length = GetComponent<SpriteRenderer>().bounds.size.x;
}
// Update is called once per frame
void Update()
{
float dist = (cam.transform.position.x * parallaxEffect);
transform.position = new Vector3(startpos + distance, transform.position.y, transform.position.z);
}
}
I am not super good at C#, especially with all of the extra things added by unity, so I dont know exactly what the problem is. Thanks in advance!