S
S
sergey_gomitr2018-11-06 18:02:32
C++ / C#
sergey_gomitr, 2018-11-06 18:02:32

NullReferenceException object reference not set to an instance of an object DetectClicks.OnMouseDown () (at Assets/Scripts/DetectClick.cs:19)?

//using
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
//public
public class DetectClicks : MonoBehaviour {

    public GameObject buttons;
    public Text playTxt, gameName;
    //private bool
    private bool clicked;

    // void
    void OnMouseDown () {
        if (!clicked) {
            clicked = true;
            playTxt.gameObject.SetActive (false);
            gameName.text = "            0"; //  изменяется название игры на очки игры
<blockquote>            buttons.GetComponent <ScrollObjects> ().speed = 5f; // уезжание вниз кнопкам
            buttons.GetComponent <ScrollObjects> ().checkPos = 5f; //</blockquote>
        }
    }

}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-11-06
@NeiroNx

Translate? The reference does not point to an instance of an object. It is necessary to check objects before manipulating them.

D
Denis Gaydak, 2018-11-06
@MrMureno

First, edit the markup of the question)

//будет нормально отображать
buttons.GetComponent<SOME_SCRIPT>().checkPos = 5f;

also get used to applying the error log COMPLETELY.
Unity writes the line number and call stack perfectly)
and the error speaks for itself, you are accessing an object whose reference is essentially empty.
or have not assigned the
buttons field in the editor;
playTxt,
gameName;
or the component that you are looking for on buttons - does not exist there. (forgot to hang it)
or look for it on a disabled object (can't find a disabled one)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question