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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Help] Comparing Values of two gameobjects

Discussion in 'Scripting' started by Ezekiel, Jul 15, 2015.

  1. Ezekiel

    Ezekiel

    Joined:
    Mar 12, 2013
    Posts:
    2
    Hello hello Everyone,

    I got a bit of a doozy here, I currently am trying to work on a pet project of mine, and have run into a snag.

    In short for those who have played triple triad, I am attempting to replicate the card system, however cannot figure out how to compare two game objects once played.

    I have built a database using the following format
    Code (CSharp):
    1. items.Add(new Item("Bob", 4,5,6,7));
    When played, (there is a small game object defining the points where the cards "lock" once played) how can i have it check the surrounding tiles to see if there is a card with the "enemy"(or similar tag) and check the variables set by the database, and compare the two.

    for those not familiar with Triple Triad, the following link will provide a description of the game
    Thanks for the help!
     
  2. massey_digital

    massey_digital

    Joined:
    Apr 28, 2013
    Posts:
    94
    Hey Ezekiel,

    I've never played triple triad, but you can keep track of the objects using a 2d array in your scene. One solution could be to use a for statement to set a temp variable through one row or column of the 2d array. Use an if statement to check if the next object in the sequence has the same value (Id maybe).

    The code below is a general idea of what I'm talking about. You'll need to edit it to make it work with your needs.

    int[,] table = new int[3,3]
    int temp = 0;
    for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
    temp = table[i,j];
    if(temp == table[i+1,j]
    {Debug.Log("Sequence!");
    }
    }

    Hope that helps!