C
C#2y ago
microX

✅ 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...)
c#
public void tictactoeButton(int WhichNum)
{
tictactoespaces[WhichNum].GameObject = playerIcons[playerIcons];



//...

if(playerTurn == 0)
{
playerTurn = 1;
}
else
{
playerTurn = 0;
}
}
c#
public void tictactoeButton(int WhichNum)
{
tictactoespaces[WhichNum].GameObject = playerIcons[playerIcons];



//...

if(playerTurn == 0)
{
playerTurn = 1;
}
else
{
playerTurn = 0;
}
}
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:
c#
public void tictactoeButton(int WhichNum)
{
tictactoespaces[WhichNum].image.sprite = playerIcons[playerIcons];



//...

if(playerTurn == 0)
{
playerTurn = 1;
}
else
{
playerTurn = 0;
}
}
c#
public void tictactoeButton(int WhichNum)
{
tictactoespaces[WhichNum].image.sprite = playerIcons[playerIcons];



//...

if(playerTurn == 0)
{
playerTurn = 1;
}
else
{
playerTurn = 0;
}
}
15 Replies
mtreit
mtreit2y ago
That error is implying that tictactoespaces is an array of Button objects. Is it an array of Button objects?
microX
microXOP2y ago
yes
microX
microXOP2y ago
microX
microXOP2y ago
@mtreit
mtreit
mtreit2y ago
So, Button objects presumably have a property called image but do not have a property called GameObject It's case sensitive
mtreit
mtreit2y ago
Looks like gameObject is the property name
mtreit
mtreit2y ago
That's the type name. Type names and property names are entirely different things. The property name could be anything
microX
microXOP2y ago
so wait are u saying i should do tictactoespaces[WhichNum].gameObject = playerIcons[playerTurn];? or tictactoespaces[WhichNum].image.gameObject = playerIcons[playerTurn];?
mtreit
mtreit2y ago
You're missing a period in there...
microX
microXOP2y ago
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
mtreit
mtreit2y ago
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.
microX
microXOP2y ago
ha ah*
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server