- Home /
Question by
AlexZapper2026 · Apr 01, 2020 at 10:05 AM ·
c#2d game
Why cant i give this script to my character? Its simple, i'm just trying something and i need this to work.
using UnityEngine;
public class ExampleClass : MonoBehaviour { public float thrust = 1.0f; public Rigidbody rb; public GameObject Blue_Player;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.W))
{
rb.AddForce(transform.forward * thrust);
}
}
}
Comment
What exactly seems to be the problem? What do you mean by "I cant give the script to the character"? Did you try clicking "Add Component" in the inspector and didn't find your script? If so, make sure the class name (ExampleClass) and the file name (ExampleClass.cs) are identical.
Answer by bzone_mx · Apr 01, 2020 at 10:53 AM
Have you tried attaching the script to the gameObject?
Your answer
![](https://koobas.hobune.stream/wayback/20220612230238im_/https://answers.unity.com/themes/thub/images/avi.jpg)