#buttons

1 messages · Page 1 of 1 (latest)

forest belfry
#

making a thread

granite sable
#

ok

#

so how can i fix my problem

forest belfry
#

Show me the inspector for the button again.

granite sable
forest belfry
#

Oh

#

I get it

#

You named your class Button

granite sable
#

yes

forest belfry
#

So your Button field is talking about your Button class

#

not Unity's Button class

granite sable
#

ok

forest belfry
#

And GetComponent<Button> got itself

granite sable
#

so what should i change?

forest belfry
#

Rename your class to something else.

#

here's how you want to do that

#
  1. In Unity, rename the script asset in the Project window to PlayAgainButton.
  2. In your code editor, rename the class from Button to PlayAgainButton
#

If you just rename the file outside of Unity, it will think you deleted the old script and made a new script.

granite sable
forest belfry
#
public class Button : MonoBehaviour

replace that with

public class PlayAgainButton : MonoBehaviour
#

Just make it so the name isn't Button.

granite sable
#

still thaht

forest belfry
#

You have the Button component enabled.

#

The if statement will never succeed.

#

because the second conditions is restartd.enabled == false

granite sable
#

Omg

#

finally

#

thank you

forest belfry
#

no problem!

#

the same-name problem can be very tricky

#

you had two different problems like that, actually

granite sable
#

How do you learn all that stuff

forest belfry
#
  1. the wrong using statement gave you the wrong Image class
  2. your Button hid unity's UnityEngine.UI.Button
forest belfry
granite sable
#

but when i google such problems i cant find anything

#

its working but i got a new problem

forest belfry
#

Something on line 21 is null

#

Clicking on the error in the console -- just once -- will highlight the object in the hierarchy

#

(While the game is running, at least)

granite sable
#

ah

#

my main camera

forest belfry
#

Sounds like you have an extra copy of the component on it

#

you probably didn't want that

granite sable
#

ok

#

why has it be so complicated all the time

forest belfry
short lantern
#

@granite sable Hello! I want to make a note for you, whenever you deal with Null References try to do something like

{
  Do that thing you want!
}

Else 
{
  Debug.Log("Value is null it has no reference!")
}```

Also, check your components in the inspector like @forest belfry told you maybe you have not assigned an ``Audio Clip`` or ``Animation`` or whatever it is maybe a ``text`` so that's why it says that it is null you have no reference, so if you have no reference then how it's going to know what you want to do. That makes sense! Hope I helped you!
granite sable
#

Thank you

short lantern
#

@granite sable Have you dealt with that issue? Can I leave this thread if you done with that and need no help anymore?