Hiii I’m working on a 2d platformer, and written a simple script, but when I want to add it to my player, I get this error: “Can’t add script behaviour AssemblyInfo. The script needs to derive from MonoBehaviour!”
I don’t know what i’m doing wrong, but since i’m still a beginner with C#, PLS HELP!!
this is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb2d;
// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
}
}
I have the same issue, although my file is named the same as the class name and it is stored under Scripts folder of the project. Additionally my unity editor says, “Assembly has reference to non-existent assembly ‘Unity.ugui’ (Packages/com.unity.textmeshpro/Scripts/Runtime/Unity.TextMeshPro.asmdef)” Are these linked?
I had the same problem. Turns out it was caused by another, unrelated script that caused ‘red’ error in Unity. When I fixed that error I was able to attach scripts to objects again.