Search Unity

Question NullReferenceException: Object reference not set to an instance of an object skor.Update

Discussion in 'Scripting' started by AldaniNaja_Student, Dec 16, 2022.

  1. AldaniNaja_Student

    AldaniNaja_Student

    Joined:
    Dec 16, 2022
    Posts:
    2
    Hi so ive had an assignment this day. I'm supposed to make a simple game with unity. I am know in steps for making score board. but everytime I try to play it. there's error that said:

    NullReferenceException: Object reference not set to an instance of an object
    skor.Update () (at Assets/Script/skor.cs:17)

    This is the script I used.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class skor : MonoBehaviour
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         PlayerPrefs.SetInt ("skor", 0);
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         GetComponent<Text> ().text = PlayerPrefs.GetInt ("skor").ToString();
    18.     }
    19. }
    20.  
    is there any ideas how to fix it?
     
  2. AldaniNaja_Student

    AldaniNaja_Student

    Joined:
    Dec 16, 2022
    Posts:
    2
    and btw this is the unity tab
     

    Attached Files: