Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help checking if a object has been clicked in another script.

Discussion in 'Scripting' started by MortisFillius, Jul 24, 2014.

  1. MortisFillius

    MortisFillius

    Joined:
    Feb 10, 2014
    Posts:
    14
    So I want to make a tic tac toe game but with as little GUI functions at possible.
    So is it possible to check if an object has been clicked and what object it was and then do something with that?
    Hopefully you guys understand cause you are smart people.
     
  2. XXJOHNATHANXX

    XXJOHNATHANXX

    Joined:
    Jul 12, 2012
    Posts:
    8
    Well there is 9 boxes, two teams, each team has its own symbol. With that logic you will need to put a turn based system with the addition of a click-to-place symbol in one of the boxes. So once Player 1 clicks on a box(likely a raycast that checks if a symbol is allready there, and if there is nothing then place it down) then the turn is Player 2, and the proccess starts over again. Then you need to check the boxes to see if there is any 3 of the same symbols lined up and whoever owns that symbol wins. Thats my run down of it anyways. Sorry that i can't help with the code, im just a noob..
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    What you're looking for is a raycast.

    Have 9 box colliders representing your 9 squares; perform a raycast using mouse position (as shown in the examples); then use hit.collider to determine which object you hit.
     
  4. MortisFillius

    MortisFillius

    Joined:
    Feb 10, 2014
    Posts:
    14

    Thanks a lot guys. I had a suspicion that i had to use raycast but wasn't sure.
    Thanks for confirming it and Helping me!
     
  5. Pysassin

    Pysassin

    Joined:
    Dec 27, 2012
    Posts:
    87