why doesnt change my money float?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Money : MonoBehaviour {

public float money = 100;
public float Prize = 0;

// Use this for initialization
void Start () {
    GetComponent<Text>().text = money.ToString();
}

// Update is called once per frame
void Update () {
    GetComponent<Text>().text = money.ToString();
}

public void BuyAHouse()
{
    Debug.Log("test");
    money = Prize;
}

}

Are you calling the “BuyAHouse()” method anywhere at all? Does your debug show in the console?

You should cache your Text component also instead of using GetComponent all the time.

You should also only change the text value when the money value is changed, rather than updating it all the time.

//cache for Text component
private Text txt;

public float money = 100f;
public float prize = 0f;

void Start()
{
     //caching the component in Start()
     txt = GetComponent<Text>();

     txt.text = money.ToString();
}

void Update()
{
       //press "X" key to call BuyHouse() method
       if(Input.GetKeyDown(KeyCode.X)) BuyHouse();
}

void BuyHouse()
{
      Debug.Log("Buying A House...");
      money = prize;
      txt.text = money.ToString();
}

it is working but the console is saying Object reference not set to an instance of an object

Script line: txt.text = money.ToString();