✅ object types?
hey ive been following this video on how to make tictactoe, for a class assignment, (https://youtu.be/AzPgov_stdI?list=PLWeGoBm1YHVj7cYQSglzBU0gb7ecDNf4g)
this guy uses images for his X's and O's. i decided to make gameObjects out of 3Dobjects (bc my teacher is not smart and would accuse me of cheating if i use pictures...)
i have this code here which is supposed to mark the spaces when you click them. but i get this error, when i save: Assets\scripts\NewBehaviourScript.cs(39,35): error CS1061: 'Button' does not contain a definition for 'GameObject' and no accessible extension method 'GameObject' accepting a first argument of type 'Button' could be found (are you missing a using directive or an assembly reference?)
any help? this is his code btw:
15 Replies
That error is implying that tictactoespaces is an array of Button objects. Is it an array of Button objects?
yes
@mtreit
So, Button objects presumably have a property called
image
but do not have a property called GameObject
It's case sensitiveLooks like
gameObject
is the property namewhy right here is it
GameObject
? https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.htmlThat's the type name.
Type names and property names are entirely different things.
The property name could be anything
so wait
are u saying i should do
tictactoespaces[WhichNum].gameObject = playerIcons[playerTurn];
? or tictactoespaces[WhichNum].image.gameObject = playerIcons[playerTurn];
?You're missing a period in there...
i get this now:
Assets\scripts\NewBehaviourScript.cs(39,9): error CS0200: Property or indexer 'Component.gameObject' cannot be assigned to -- it is read only
Well, apparently the intent is not for you to write to that property.
I don't know Unity so I have no idea if what you are trying to do makes sense.
But sounds like you are on the wrong track.
You might ask for help in #game-dev , there are people who know Unity there.
ha
ah*
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.