Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Reigns Game - Problem with INSPECTOR UI and new "cards"

Discussion in 'Scripting' started by xamur, Sep 27, 2016.

  1. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Hello folks,
    I hope the title is interesting enough, so many people look at this question.
    I'm currently working on a Project which contains 2D and 3D elements. This game works like the mobile game "Reigns" and is very simple:

    In the center of the main camera is an image, The image should be a "card". It isn't 2D (so no UI or sprite), I used a 3D cube, so I could write a moving script for it myself. Above the card there is a textfield which is a question. You can move the card to the left (there is a trigger) and also to the right (another trigger). Left means that you reply to the question with "Yes" or, when you move it to the right, with "No".

    It's not important in this case if you answer with "Yes" or "No", because after the card exits one of the trigger (OnTriggerExit) , then a new question and a new card should appear, but that does not really work.
    Everything works fine for the first randomized card!

    Now to my Problem:

    At the beginning within the method void Start() a number gets randomized. After that, the if-statement within the method void checkingCards() tries to find out which card and question will appear when (for example) number 3 gets generated randomly.
    Until here everything works, as I said!

    When I reply now with "Yes" or "No" a second/new random number should be generated and another card and question should appear.

    This step doesn't work correctly and I don't know exactly how I could solve it, because I tried so many things and nothing worked yet.

    If anyone understood what I want to achieve then I would appreciate any help which helps. If you don't got what I wanted to say just tell me and I try to explain better.



    I use this parts of my scripts to do these steps of my project:

    GameManager.cs
    Code (CSharp):
    1. public void Start()
    2.     {
    3.         //We check which card will be the first and who is asking us.
    4.         rdmNumber = Random.Range(1, 6);
    5.  
    6.         checkingCards();
    7.     }
    8.  
    9.     public void checkingCards()
    10.     {
    11.  
    12.         if (rdmNumber > 5)                      //When the random number is higher than 5 it will be card6
    13.         {
    14.             cards[6].SetActive(true);
    15.             characterName.text = "Some character name";
    16.             characterQuestion.text = "Some text of the character";
    17.  
    18.             lifetime += 1;                     //Increases the lifetime of the player +1 with every drawn card, because a new card means one year later.
    19.             yearsOfLive.text = lifetime.ToString();
    20.             Debug.Log(characterName.text + " asked you something.");
    21.         }
    22.  
    23.         else if (rdmNumber > 4)
    24.         {
    25.             cards[5].SetActive(true);
    26.             characterName.text = "Some character name";
    27.             characterQuestion.text = "Some text of the character";
    28.  
    29.             lifetime += 1;
    30.             yearsOfLive.text = lifetime.ToString();
    31.             Debug.Log(characterName.text + " asked you something.");
    32.         }
    33.  
    34.         else if (rdmNumber > 3)
    35.         {
    36.             cards[4].SetActive(true);
    37.             characterName.text = "Some character name";
    38.             characterQuestion.text = "Some text of the character";
    39.  
    40.             lifetime += 1;
    41.             yearsOfLive.text = lifetime.ToString();
    42.             Debug.Log(characterName.text + " asked you something.");
    43.         }
    44.  
    45.         else if (rdmNumber > 2)
    46.         {
    47.             cards[3].SetActive(true);
    48.             characterName.text = "Some character name";
    49.             characterQuestion.text = "Some text of the character";
    50.  
    51.             lifetime += 1;
    52.             yearsOfLive.text = lifetime.ToString();
    53.             Debug.Log(characterName.text + " asked you something.");
    54.         }
    55.  
    56.         else if (rdmNumber > 1)
    57.         {
    58.             cards[2].SetActive(true);
    59.             characterName.text = "Some character name";
    60.             characterQuestion.text = "Some text of the character";
    61.  
    62.             lifetime += 1;
    63.             yearsOfLive.text = lifetime.ToString();
    64.             Debug.Log(characterName.text + " asked you something.");
    65.         }
    66.  
    67.         else
    68.         {
    69.             cards[1].SetActive(true);
    70.             characterName.text = "Some character name";
    71.             characterQuestion.text = "Some text of the character";
    72.  
    73.             lifetime += 1;
    74.             yearsOfLive.text = lifetime.ToString();
    75.             Debug.Log(characterName.text + " asked you something.");
    76.         }
    77.     }
    YES.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class YES : MonoBehaviour //This is the class for the trigger on the left side, the "Yes"-Trigger. (The "No"-Trigger-Script will look the same as here)
    5. {
    6.     public GameManager gManager;
    7.     public static bool activateMoving = false;
    8.     public static bool movingDone = false;
    9.  
    10.     public static Vector3 startPos;
    11.  
    12.     void Start()
    13.     {
    14.         startPos = new Vector3(0, 0, 0);
    15.     }
    16.  
    17.     void OnTriggerEnter(Collider col)
    18.     {
    19.         if (col.gameObject.tag == "card")
    20.         {
    21.             GameManager.answeredYes = true;
    22.             Debug.Log("You choosed yes.");
    23.             activateMoving = true;
    24.  
    25.         }
    26.     }
    27.  
    28.     public void OnTriggerExit()
    29.     {
    30.         activateMoving = false;
    31.         movingDone = true;
    32.         gManager.Start();
    33.     }
    34. }
    MoveCard.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MoveCard : MonoBehaviour //Because of that the card will be moved to a position and then to its start position, so I can use it again, again, again and again... (that's the idea ^^ but as you can see it doesn't work)
    5. {
    6.     public GameManager gManager;
    7.  
    8.     private float speed = 1;
    9.     private YES yes;
    10.  
    11.  
    12.  
    13.     public void Update()
    14.     {
    15.  
    16.         if (YES.activateMoving == true)
    17.         {
    18.             transform.Translate(-speed * Time.deltaTime, 0, 0);
    19.         }
    20.         else if (YES.movingDone == true)
    21.         {
    22.             transform.position = YES.startPos;
    23.             gameObject.SetActive(false);
    24.             Debug.Log("Moved");
    25.          
    26.         }
    27.     }
    28. }
    The second generated card/image doesn't gets activated or shown, that means that I cannot drag it (because it's invisible/deactivated) and the other problem is that another random number doesn't gets generated as well. Only the question changes but stops then, because there is no second/new card which could be dragged through one of the triggers.
     
    Last edited: Sep 27, 2016
  2. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    Goodness gracious this is a well edited post :) .

    Now, your problem can be solved quite easily. Let's walk together trough your code.

    For GameManager.cs:
    • change the name of your start function to something like GenerateCards.
    • add a new function called ResetCards. In this function you should iterate trough each value of cards array and make the card object invisible and reset the transform position the starting state.
    For YES.cs:
    • remove gManager.Start()
    • replace it with gmManager.ResetCards()
    MoveCard.cs can remain unchanged.

    Do this modification, then check if there are any values left that need to be reset. The idea is that all initializations should be done in GenerateCards, and all values should be rested in ResetCards
     
  3. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Haha, thanks! I gived my best to make it easy to understand. I don't wanted that it takes to long to understand just because I wrote everything down like an idiot. ^^

    Could you explain this step a little bit more? What should I "reset"? I think I got what you meaned but I'm not quite sure. Should I reset every variable I use to 0/null, also textfields? Please explain. :p ^^

    Edit:

    Well, I have now done it like that:

    GameManager.cs
    Code (CSharp):
    1. public void GenerateCards()
    2.     {
    3.         //We check which card will be the first and who is asking us.
    4.         rdmNumber = Random.Range(1, 6);         //Randomized number between 1 and 6 >> increase or decrease.
    5.  
    6.         checkingCards();
    7.     }
    8.  
    9.     public void ResetCards()
    10.     {
    11.         cards[6].SetActive(false);
    12.         cards[6].transform.position = YES.startPos;
    13.         cards[5].SetActive(false);
    14.         cards[5].transform.position = YES.startPos;
    15.         cards[4].SetActive(false);
    16.         cards[4].transform.position = YES.startPos;
    17.         cards[3].SetActive(false);
    18.         cards[3].transform.position = YES.startPos;
    19.         cards[2].SetActive(false);
    20.         cards[2].transform.position = YES.startPos;
    21.         cards[1].SetActive(false);
    22.         cards[1].transform.position = YES.startPos;
    23.  
    24.     }
    YES.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class YES : MonoBehaviour
    5. {
    6.     public GameManager gManager;
    7.     public static bool activateMoving = false;
    8.     public static bool movingDone = false;
    9.  
    10.     public static Vector3 startPos;
    11.  
    12.     void Start()
    13.     {
    14.         startPos = new Vector3(0, 0, 0);
    15.     }
    16.  
    17.     void OnTriggerEnter(Collider col)
    18.     {
    19.         if (col.gameObject.tag == "card")
    20.         {
    21.             GameManager.answeredYes = true;
    22.             Debug.Log("You choosed yes.");
    23.             activateMoving = true;
    24.  
    25.         }
    26.     }
    27.  
    28.     public void OnTriggerExit()
    29.     {
    30.         activateMoving = false;
    31.         movingDone = true;
    32.         gManager.ResetCards(); //Changed gManager.Start() to gManager.ResetCards();
    33.     }
    34. }
    But, as I already have thought, when I hit play nothing happens, or at least, the first card (of the old void Start() function) does not appear. Why? Because I changed void Start() to void GenerateCards() as you said. ^^
     
    Last edited: Sep 27, 2016
  4. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    Yeah, you need to call GenerateCards for the first time, depending when you want to start your sequence,. Don't be afraid to experiment, even if you break your code! You can simply define a new Start function and call GenerateCards from that.

    Also you can write reset cards as:
    Code (CSharp):
    1. for(int i = 0; i <= cards.Length; i++)
    2. {
    3.   cards[i].setActive(false);
    4.   cards[i].transform.position = YES.startPos
    5. }
    Here is a tutorial for loops.

    By reset I mean everything that doesn't look right when you generate new (recycled) cards. You will have to experiment and try your code to see if you encounter any problems. Maybe you will need to reset rotation, scale, color, etc... Everything that need to be set to the initial state will go into the Reset cards.

    Also, after you call ResetCards, you need to call GenerateCards to get a new batch.
    It will work like this:
    GenerateCards -> ResetCards and GenerateCards -> ResetCards and GenerateCards ->...
     
  5. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Ahh thanks!

    Hopefully, you'll help me eventually a little bit more? ^^

    I changed everything like you said and also changed the code of mine with the code of yours for the method ResetCards().
    By the way, I get this error because of the array list of your code:
    But it doesn't work. It feels like nothing changed.
    If I hit play, the first card appears + question etc. When I move the card to the left (for answering it with "Yes", because of the trigger) nothing happens. The card disappears and the second card doesn't get activated. :(
     
    Last edited: Sep 27, 2016
  6. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    @CloudKid had the right idea but a small bug
    change the loop to this:
    Code (CSharp):
    1. // Change <=  to just <
    2. for(int i = 0; i < cards.Length; i++)
    cards.Length will return the number 6 (How many cards are in your array)
    but we want to loop from 0 to 5. so we have to be strictly < 6 not <=6

    To make the next card appear you need to change the OnTriggerExit in Yes.CS to reset the cards AND call Generate New cards:
    Code (CSharp):
    1. public void OnTriggerExit()
    2.     {
    3.         activateMoving = false;
    4.         movingDone = true;
    5.         gManager.ResetCards(); //Changed gManager.Start() to gManager.ResetCards();
    6.         gManager.GenerateCards();
    7.     }
    8.  
     
    CloudKid likes this.
  7. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    For some reason I always make mistakes like that when writing code directly in the Code tag thingy, thanks for help :D

    Yeah, as I said :
    Did you add the GenerateCards part?
     
  8. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Thank you @takatok, no error anymore.


    For me it makes sense that I have to add gManager.GenerateCards(); to OnTriggerExit, too. I did it. But the next card still doesn't gets activated.

    If I move the first generated card to the trigger, and after it exits the trigger it disappears (does what it should) but no new card appears, only the question.
     
  9. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    Is "YES.startPos" the right default position value?

    You can test what is the actual default position of your cards by pausing after the first car appeared, then move it in the hierarchy menu in such a way that it has no parents (so you will see in editor the actual position, instead of local position). Then look in the inspector at the transform component.

    To do the same thing programmatically, you could define a private variable called initialPosition, and set in Start to the position of one of the cards. You could even make it public and set it by hand in Inspector. Then, on Reset, change each card position to that initialPosition.
     
  10. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Well, if I "unparent" the first card in pause mode the coordinates are 0, 0, 0. which is equal to YES.startPos;
    :/
     
  11. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    Is CheckingCards still the same as your original post?
    A few quick notes.
    1. This is going to crash at some point.
    Code (CSharp):
    1. cards[6].SetActive(true);
    arrays in c# start at 0 not 1. So your cards are actuall cards[0], cards[1], cards[2],cards[3],cards[4],cards[5] thats 6 cards. So card[6] would be the 7th card and it doesn't exist. You'll want to drop all your card numbers by 1.

    2. Random.Range(a,b) when dealing with integers excludes the upper number. So this line:
    Code (CSharp):
    1. rdmNumber = Random.Range(1, 6);  
    will give you a number 1-5.
    If you make the change I pointed out above in 1. (so your going form 0->5 not 1-6 then just change your Random to this:
    Code (CSharp):
    1. rdmNumber = Random.Range(0, 6);  
    Now its going to be 0->5 as well.

    Now as to why its not showing. Are you sure your positions are correct in ResetCards
    Code (CSharp):
    1. cards[6].transform.position = YES.startPos;
    If Yes.startPos is somewhere off screen then the card IS showing you just can't see it because its offscreen

    Do you actually have more than 6 cards? I can't believe this isn't giving you errors:
    Code (CSharp):
    1.  cards[6].SetActive(false);
    2. cards[6].transform.position = YES.startPos;
    cards[6] should be throwing all kinds of fits if you only have 6 cards. Since like I said c# runs from 0 to 5. Unless you are coding in different language that can use a 1-based index for arrays?
     
    CloudKid likes this.
  12. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    So, do you mean I should change it everytime I use "cards[number]"? I mean, if I take "cards[1]", should I change it to "cards[0]" and "cards[6]" to "cards[5]" for example?


    rdmNumber is float, not int. Does it make a difference?
    I changed both now.


    As I already said, it should be 0, 0, 0.
    And I am sure it isn't offscreen because I can see in the Hierarchy how the card gets deactivated after OnTriggerExit but a new card doesn't gets activated.


    I already changed that to the loop both of you gaved me. And I am using C# for every script.
    Code (CSharp):
    1. public void ResetCards()
    2.     {
    3.         for (int i = 0; i < cards.Length; i++)
    4.         {
    5.             cards[i].SetActive(false);
    6.             cards[i].transform.position = new Vector3 (0, 0, 0);
    7.         }
    8.     }

    Perhaps I have overlooked something.
    HERE ARE MY UPDATED SCRIPT PARTS SO FAR!


    GameManager.cs

    Code (CSharp):
    1. public void Start()
    2.     {
    3.         GenerateCards();
    4.     }
    5.  
    6.     public void GenerateCards()
    7.     {
    8.         //We check which card will be the first and who is asking us.
    9.         rdmNumber = Random.Range(0, 6);         //Randomized number between 1 and 6 >> increase or decrease.
    10.  
    11.         checkingCards();
    12.     }
    13.  
    14.     public void ResetCards()
    15.     {
    16.         for (int i = 0; i < cards.Length; i++)
    17.         {
    18.             cards[i].SetActive(false);
    19.             cards[i].transform.position = new Vector3 (0, 0, 0);
    20.         }
    21.     }
    22.  
    23.     public void checkingCards()
    24.         {
    25.  
    26.             if (rdmNumber > 5)                      //When the random number is higher than 5 it will be card6
    27.             {
    28.                 cards[6].SetActive(true);
    29.                 characterName.text = "Some character name";
    30.                 characterQuestion.text = "Some text of the character";
    31.  
    32.                 lifetime += 1;                     //Increases the lifetime of the player +1 with every drawn card, because a new card means one year later.
    33.                 yearsOfLive.text = lifetime.ToString();
    34.                 Debug.Log(characterName.text + " asked you something.");
    35.             }
    36.  
    37.             else if (rdmNumber > 4)
    38.             {
    39.                 cards[5].SetActive(true);
    40.                 characterName.text = "Some character name";
    41.                 characterQuestion.text = "Some text of the character";
    42.  
    43.                 lifetime += 1;
    44.                 yearsOfLive.text = lifetime.ToString();
    45.                 Debug.Log(characterName.text + " asked you something.");
    46.             }
    47.  
    48.             else if (rdmNumber > 3)
    49.             {
    50.                 cards[4].SetActive(true);
    51.                 characterName.text = "Some character name";
    52.                 characterQuestion.text = "Some text of the character";
    53.  
    54.                 lifetime += 1;
    55.                 yearsOfLive.text = lifetime.ToString();
    56.                 Debug.Log(characterName.text + " asked you something.");
    57.             }
    58.  
    59.             else if (rdmNumber > 2)
    60.             {
    61.                 cards[3].SetActive(true);
    62.                 characterName.text = "Some character name";
    63.                 characterQuestion.text = "Some text of the character";
    64.  
    65.                 lifetime += 1;
    66.                 yearsOfLive.text = lifetime.ToString();
    67.                 Debug.Log(characterName.text + " asked you something.");
    68.             }
    69.  
    70.             else if (rdmNumber > 1)
    71.             {
    72.                 cards[2].SetActive(true);
    73.                 characterName.text = "Some character name";
    74.                 characterQuestion.text = "Some text of the character";
    75.  
    76.                 lifetime += 1;
    77.                 yearsOfLive.text = lifetime.ToString();
    78.                 Debug.Log(characterName.text + " asked you something.");
    79.             }
    80.  
    81.             else
    82.             {
    83.                 cards[1].SetActive(true);
    84.                 characterName.text = "Some character name";
    85.                 characterQuestion.text = "Some text of the character";
    86.  
    87.                 lifetime += 1;
    88.                 yearsOfLive.text = lifetime.ToString();
    89.                 Debug.Log(characterName.text + " asked you something.");
    90.             }
    91.         }

    YES.cs

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class YES : MonoBehaviour
    5. {
    6.     public GameManager gManager;
    7.     public static bool activateMoving = false;
    8.     public static bool movingDone = false;
    9.  
    10.     public static Vector3 startPos;
    11.  
    12.     void Start()
    13.     {
    14.         startPos = new Vector3(0, 0, 0);
    15.     }
    16.  
    17.     void OnTriggerEnter(Collider col)
    18.     {
    19.         if (col.gameObject.tag == "card")
    20.         {
    21.             GameManager.answeredYes = true;
    22.             Debug.Log("You choosed yes.");
    23.             activateMoving = true;
    24.  
    25.         }
    26.     }
    27.  
    28.     public void OnTriggerExit()
    29.     {
    30.         activateMoving = false;
    31.         movingDone = true;
    32.         gManager.ResetCards();
    33.         gManager.GenerateCards();
    34.     }
    35. }

    MoveCard.cs

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MoveCard : MonoBehaviour
    5. {
    6.     public GameManager gManager;
    7.  
    8.     private float speed = 1;
    9.     private YES yes;
    10.  
    11.  
    12.  
    13.     public void Update()
    14.     {
    15.  
    16.         if (YES.activateMoving == true)
    17.         {
    18.             transform.Translate(-speed * Time.deltaTime, 0, 0);
    19.         }
    20.         else if (YES.movingDone == true)
    21.         {
    22.             transform.position = YES.startPos;
    23.             gameObject.SetActive(false);
    24.             Debug.Log("Moved");
    25.  
    26.         }
    27.     }
    28. }

    By the way, this is what happens at the moment in scene (it's just a GIF):
    CLICK ME
     
    Last edited: Sep 28, 2016
  13. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Do you or someone else have an idea?
     
  14. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    Well obviously your code from that Image is a little different than what you posted:
    Code (CSharp):
    1. else if (rdmNumber > 4)
    2.             {
    3.                 cards[5].SetActive(true);
    4.                 characterName.text = "Some character name";
    5.                 characterQuestion.text = "Some text of the character";
    6.                 lifetime += 1;
    7.                 yearsOfLive.text = lifetime.ToString();
    8.                 Debug.Log(characterName.text + " asked you something.");
    9.             }
    Because I"m seeing the actual questions and the actual names of poeple on yoru image.. not these text above:)

    The fact that the question and the name are changing in your Image suggests you are actually changing the card in the If/Else statements. So cards[x] is actually getting set Active. The problem might be something else. What are cards (Object wise?) how are you displaying that red box? These might be messing up even though your activating the card.
     
  15. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    No, it is not, the GIF I posted earlier was only made with Photoshop to show you what it looks like at the moment. The question text and name text etc. was only for demonstrating.

    I guessed as much.
    The cards are ("hard coded" and just) prefabs. It is a cube which has the perfect size and fits perfectly for my needs. I tried to use only UI for this project but then it didn't work that the card moves when I wanted to drag it with the mouse.

    All cards are attached on the GameManager.cs script, this script is attached to an empty gameobject in the Hierarchy called "GameManager" (first image). The cards are childs of the canvas and also a child of an empty gameobject called "CardsManager", just for visual appearence, it doesn't have any script attached on it (second image).


     
    Last edited: Sep 30, 2016
  16. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Okay, I found something! At the line where all the "<<<<<<<<" are.
    In MoveCard.cs
    Code (CSharp):
    1.     public void Update()
    2.     {
    3.  
    4.         if (YES.activateMoving == true)
    5.         {
    6.             transform.Translate(-speed * Time.deltaTime, 0, 0);
    7.         }
    8.         else if (YES.movingDone == true)
    9.         {
    10.             transform.position = YES.startPos;
    11.             //gameObject.SetActive(false);  <<<<<<<<<<<
    12.             Debug.Log("Moved");
    13.      
    14.         }
    15.     }
    16. }
    Because of that line I set the gameobject on every frame (because of Update()) as deactivated. I solved the problem now, that a new card will not be activated. Now a new card appears.
    But I have a new problem.

    When the first card disappears and a new one appears I cannot drag the newly generated card. It is only there (but the old one gets deactivated, if I look in the Hierarchy)!

    What could THAT be? :/

    EDIT:

    Alright, solved that, too.
    I only had to add "YES.movingDone = false;" to the if-satement in MoveCard.cs "if (YES.movingDone == true)", because, of course, when it is always set to true it cannot be moved anymore. :)
     
    Last edited: Oct 2, 2016
  17. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Hello again.
    I don't wanted to open a new thread because everything else is already explained here. Today I have another problem or question. I want to make the handling of this project a little bit easier, so I started to think about something like this for the Inspector:


    (Only photoshopped)

    I want that everything looks the same or just similar in unity and works equal to this concept. I want that I can add new questions easily without coding myself and also add values which will increase or decrease the amount of a main value of every fraction in my game.

    If you don't understand:
    I have 4 fractions in this game. Every fraction has a start amount of 50 (int) and begins with it. Now, when I choose YES, I want that I can set and edit the value of the different values of the fractions which will modify the starting value.
    As you can see here:

    Code (CSharp):
    1. Fraction1StartAmount = 50;
    2.  
    3. If (choosedYES = true)
    4. {
    5.     fraction1StartAmount += or -=  //and then the value I set in the inspector
    6. }
    And this should work for every fraction. Does someone know how I can do somehing like that?
     
  18. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    So you want an array of Questions, that you can add on the fly. Each of these Questions would affect 4 fractions in someway. Is it the same 4 fractions each time? And I assume the user would be presented with these question each time.

    Does the base value get reset at the start of each question.. or would it be cumulative. Fraction1 starts at 50. but if Question1 changes it -20, and then Question 2 changes + 40 , then Fraction1 = 70?

    Overall your going to need to use what Unity Calls PropertyDrawers
    https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
     
    Last edited: Oct 13, 2016
  19. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Yeah, that's correct. There are only 4 fractions which will be the same for ever (e. g. church, people, army and possessions). I forgot something in my picture, I also want to be able to decide for each question, which fraction it is for. When I add a new question via the inspector (as the picture in my last post shows), this question should only be (for example) for army. That means, if the generated number is 3, then card3 will be set to active (card3 = army in this case), and only when army is activated the previously added question can be choosen (or another one that was added for this array).

    I hope you got it, if not let me know.

    It will not be resetted. When fraction1 = 50 at the beginning and then question1 is choosen (of the array of questions for THIS fraction), it will change it -20. Fraction1 is now 30. When question2 is choosen and changes the value of fraction1 +40, then fraction1 is 70, that's correct.
     
  20. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109
    Any one?
     
  21. xamur

    xamur

    Joined:
    Mar 27, 2014
    Posts:
    109