I am trying to create a top-down rpg in the most recent version of unity. I wrote a couple scripts, but they all got the script class could not be found error. I have tried multiple tutorials, ect… but they all still get the error. please help!
Player script:
using UnityEngine;
using System.Collections;
public class Player: Entity
{
void Start()
{
}
void Update()
{
if (Input.getkey(keycode.w) || Input.getkey(keycode.UpArrow))
{
rigidbody2d.transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.getkey(keycode.a) || Input.getkey(keycode.RightArrow))
{
rigidbody2d.transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.getkey(keycode.s) || Input.getkey(keycode.DownArrow))
{
rigidbody2d.transform.position += Vector3.down * speed * Time.deltaTime;
}
if (Input.getkey(keycode.d) || Input.getkey(keycode.LeftArrow))
{
rigidbody2d.transform.position += Vector3.left * speed * Time.deltaTime;
}
}
}
Entity script:
using UnityEngine;
using System.Collections;
public abstract class Entity: MonoBehaviour {
public float speed;
void Start() {
}
void Update()
{
}}
It happens when I try to drag the script into the player object. The unity error name is “can’t add script”. In visual studio, the debugger tells me that there is nothing wrong with the code.
The console will tell you what the problems are. Can you copy and paste the actual error messages with the file name and line number? The “cant add script” is most likely just a symptom of your code having compiler errors.
So, my issue is that the console is displaying no errors. Also, I managed to fix the player script, now I just need help weeding out issues with the entity script. As the player script is dependent on the entity script, It will not work properly without it.
My guess would be that you have the Player script on the player and Entity should be on your player because it’s a MonoBehavior. Also just noticed that you have resolved this issue. Always a good idea to share your solution in case someone else runs into the issue and searches bring them to your thread.