Can`t get this code to work.

Hi,

this code should look if player is closes than 10 meters to this object and then give option to pick it up. But it does not do that. Unity gives error :
NullReferenceException: Object reference not set to an instance of an object
ülevõttmine.Update () (at Assets/ülevõttmine.cs:20)
How do I fix that? This information helps me a lot, I have been stuck on this for a long time.
public class ülevõttmine : MonoBehaviour
{
int kaugus = 10; // Maximum distance that player can be away from pickupable object.
public GameObject ülesvõttja; // player that picks up the object.
public GameObject relvavahetamine; //After pickup this becomes parent of pickupable object.
public GameObject koht; // place where pickupable object is placed after the pickup.
public void ülesvõttmine()
{
this.transform.position = koht.transform.position + transform.up;
this.transform.SetParent(relvavahetamine.transform, true);
}
void Update()
{
if (Vector3.Distance(this.transform.position, ülesvõttja.transform.position) < kaugus)
{
GetComponent().aktiveerimine(); //shows text to the player that object can be picked up.
if (Input.GetButton(“f”)==true)
{ ülesvõttmine(); }
}
}
}

Post your code using code tags. It makes it easier to read, and gives line numbers so we can see where your error was happening.

Your error message says the error is on line 20. Since you did not share the entire script, it’s hard to tell which line is line 20.

Anyway the problem is most likely this line:

GetComponent<tekst>().aktiveerimine(); //shows text to the player that object can be picked up.

The reason you are getting this error is because the object this script is attached to does not have a tekst component attached to it.

https://docs.unity3d.com/Manual/NullReferenceException.html

Solved it, input was incorrectly set up. Thans for the help.