- Home /
How do i tell what gameobject im on
Hey guys, I have BoardPrefabs with there own number placed in the area, how do i tell the gameobject thats on the board what board its on ? I want this because, eventually when player 1 answers correctly, Player 2 defender will randomly move on there side to stop the player from scoring and if player 1 moves on the board same as the object, there position gets reset.
Answer by xt-xylophone · Feb 19, 2014 at 07:45 PM
I don't quite get exactly what you are saying, maybe provide a picture.
Players are moving on a board and you need to know which part of the board they're on? Try using a collider set to Trigger and inside your player scripts use the onTriggerStay function. Then you can check which trigger they are inside.
As you see from the picture, if player 1 or 2 correctly answers there question, the defenders will randomly move on there half of the pitch. there are 60 Boardspaces. so Player 1 defenders can move anywhere between boardspace 1 to 30 and P2 defenders can move anywhere between boardspace 31 to 60. Im not sure if you can use Random random on Prefabs though.
public void reset()
{
currentSpace = startSpace;
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Player2Defenders")
{
Debug.Log("I Have touched you " + "Player2Defenders");
Debug.Log("Why havent you reset£");
reset();
}
}
this doesnt seem to work
Your answer
Follow this Question
Related Questions
Prefab Script List not being assigned as unique - can you see why? 1 Answer
Unable to generate a proper engine etc... 0 Answers
Random.Range doesnt work anymore 4 Answers
How to create inheritance for unity GameObjects 2 Answers
Instances of one prefab work wrong together,OnMouseOver works wrong with instances of prefabs 0 Answers