i am new to coding and my code isnt working it alsways gives an error
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour
{
Rigidbody rb;
float speed;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
speed = 10.0f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.RightArrow))
{
//Move the Rigidbody to the right constantly at speed you define (the red arrow axis in Scene view)
rb.velocity = new Vector3(rb.velocity.x + 0.03f, rb.velocity.y, rb.velocity.z);;
}
}
Hi! Some advice on asking questions in a place like this:
When asking for help with an error, you should clearly state what’s the problem.
What did you do, what did you expect to happen and what happened.
You should really read the error message thoroughly as beginners tend to panic when errors happen and they don’t even try to understand them.
You should fix formatting of your question so all of your code is actually in a code block.
To answer your question:
I’m assuming from the looks of your inspector that you Character class is not in a file called Character.cs. For MonoBehaviours and ScriptableObjects to work properly there should be only one root class in a file that’s named exactly as the class.