• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By aymen
      please any know how can i' calculate the centroid from any number vertices
    • By Henry Fernandez
      Good day sir/maam. I am developing a game for my thesis and im done with multiplayer and plan to start the implementation of AI but i dont know how/where to start. Please give an advice. I am developing it in C# using UNITY. 
      Im am now collected all pieces that has possible moves but i am stuck on which best move to select. I hope you will help me. This is link explained the game https://en.wikipedia.org/wiki/Game_of_the_Generals 

    • By Priceman
      Firstly, hello to everyone.
      So, as the title says, i'm looking for a bit of direction for designing and programming my game idea. What i'm essentially trying to do is create a 2d side scroller along the lines of such titles as Dust: An Elysian Tail, Ori and the Blind Forest, or the Odin Sphere series. I'm currently taking courses on Udemy to learn unity and C#. I chose this route since one of my favorite indie dev studios, Ska Studios, use it making their games. I'm already a decent artist and animator, so I just need something to put the pieces together. I guess i'm looking for an opinion on if this is the best route to take for someone completely new to game development and programming. I've looked into engines like gamemaker, but for what I have in mind (progression systems, inventories, etc) it didn't seem like the way to go. RPGmaker and Unreal also don't seem to be right for what I have in mind. 
      Anyway, thanks for taking the time to help.
    • By fr0st2k
      Hello All.
      I have been working with a small team the last few months on development of a mobile RPG/gacha game, inspired by games like: Brave Frontier, Summoners War, One Piece Treasure Cruise, and even Diablo. 
      The idea behind the game is to create a fun collection game that has a good amount of strategy, with a focus on creating a true game for gamers.  Not a corporate run money grabber like the majority of mobile games.
      We have done a lot of work already on the game, however, I am at a point now where I need dedicated team members who have a passion for game development and the project.
      Take a look at some of the screenshots of the game to get an idea of where we are.
      The game involves collecting characters, and leveling them, to compete against more difficult encounters.  I took a lot of inspiration from my days playing Diablo 2.  If you boil down diablo's gameplay mechanics, you get a core game based around efficiency.  The better your items, the faster you can clear zones to the bosses, and the safer the battle with the bosses are.  After you kill the boss, you pull a slot machine lever and get more items.  The better your character(and skill), the more chances you get at pulling that slot machine lever.
      This game uses that core mechanic in a mobile environment.  Instead of running through Act3 to mephisto, you send your characters out on an 'explore' mission.  A specific amount of time goes by based on your characters power, then you fight a strategic boss fight, where you can win loot.  The explore times range from a few minutes, to hours/days.  You can speed up that time by playing a 'tap' game, similar to Tap Titans.  
      It is a great formula, and even without proper balancing, the game is already shaping up to be a lot of fun.
      --- What I need moving forward:
      Team requirements:
      1. Lead developer / Senior Programmer (unity)
      We need someone who is very fluent in unity game development, and someone who can lead a team of newer programmers. If you have been looking for a project that you can take control of, or need some resume building work that will provide a finished product to show off, this is a great position to fill, as the game is nearly complete already.
      Ideally, this candidate would be proficient in unity client and server side programming
      If you are interested in the position, we can talk profit sharing once the app launches.  (contracts will be required)
      2. Programmers
      If you are newer to programming, or just want to sharpen your skills and gain some experience on a game development team, reach out.  I'd be interested in talking to you and seeing if you are a good fit. 
      I suspect an NDA might be required, but other than that, this position would be great to hop in and out of, and again, would be a great way to contribute to a great project and gain valuable experience.
      3. Pixel Artist / Spine animator
      Either or.  I am currently getting art from a team out in Indonesia.  They are great, but hard to communicate with.  I'd love to have a dedicated artist with Spine(or any alternative 2d pixel animation) experience.  
      If you have interest in joining this team, please reply back.  Again, i'd like to reiterate, this is primarily a hobby based project.  However, it will eventually hit the app store and (ideally)generate income.  All team members will be a part of that revenue stream.
      Please respond with any questions, would be happy to respond.

    • By Nostalgic Saint

      Trap.io is a game where you collect the trap power-ups and place them and then lead the corresponding enemy (based on color) into the trap to destroy the enemy and score points.The game is endless easy to play difficult to master. The game features highly fast paced combat with an arcade-like feel to movement, to bring back the nostalgia from the past retro space shooter games. With addictive fast paced gameplay a mistake might be your last, keeping up with the fast paced flow games typically lasting 2 minutes, this game is all about fast movement and quick thinking with an element of strategy to trick your cunning, wity enemies into the traps to score points

  • Advertisement
  • Advertisement
Sign in to follow this  

Unity Data linking varibles

This topic is 760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I have X amount of variables, they all need to add up to an amount (100). There are some conditions that must be met.


  • When I set one variable, the others need to reduce/increase.
  • the variables can not go less than 0.  
  • The variables must stay at the same ratio, unless one or more is decreased to 0

Currently I have an issue where I will have a set of varibles: 1, 50, 25,24 . And I want to increase the first variable to 91.

 for (int i = 0; i < arraySize; i++)
            int SliderValue = aarray[i]
            if (SliderValue!= oldValue) //only update when changed
                int difference = SliderValue - oldValue;//how much did the slider change by
                oldValue = SliderValue; //update the old value

                int amount = difference / arraySize - 1);
                int remainder = 0;
                if (difference % arraySize - 1) != 0)//We need to know if it has rounded down
                    remainder = difference % (arraySize -1);


                for (int j = 0; j < arraySize; j++) //Change the other values
                    if (j == i)//dont change youself

                    int b = array[j];
                    if (remainder != 0 && (b>= 0 && b <= goal))
                        if (remainder < 0)
                            increaselowest(array, /*element to ignore*/i, Mathf.Abs(remainder));

                            decreaselargest(array, /*element to ignore*/i, Mathf.Abs(remainder));

                        remainder = 0;


                    b= b- amount;
                   Oldvalue= b.intValue;

 apologies if there are bugs/errors in this code. It was written using Unity serialization stuff, and had to edit it down.


increaselowest will find the lowest variable in the array and increase it by the amount.

DecreaseLargest will find the largest value and decrease it by an amount.



My problem comes when I increase by a large amount. with the numbers 1, 50, 25,24. and increase the first variable by 90, it means the other numbers need to decrease by 30 (3*30 = 90). However this will result in the last two variables being negative. 


I could reduce the other variable when a var goes negative, but I don't know how many varibles are in the list.


I cant sum the negative numbers and reduce the positive numbers by that absolute value, as that inturn may make the a number negative again.


I feel like the solution will be some recursion, but I cant think of a nice clean way to do it.


Any thoughts?

Share this post

Link to post
Share on other sites

Now that we have some real values perhaps we can discuss from chat. Note according to me pulling down 30 by each three-last variable implies you're breaking the ratio between them but I guess that's lost in translation.

a= 1, b=50, c=25, d=24 sum_abcd=100
a=91, b=50, c=25, d=24 sum_abcd=190; sub_bcd=99

a must stay 91. 100 - a = 9 (I guess that's what Madolite tried to tell you). Divide bcd by 100 and now you got a nice 3D vector if you're familiar with this. Normalize it. It'll be

b=.505050, c=.252525, d=.242424 sum_bcd=~100

This is your new 100%. Multiply those values by 9.

b=4.545454~5, c=2.272725~2, d=...~2

What a coincidence, they add up to 9.


I still haven't understood the deal with negatives. You write they cannot go lower than zero... but can start less than zero?

Try counting from the minimum.

Edited by MaxDZ8

Share this post

Link to post
Share on other sites
For the list, L=(1, 50, 25, 24), and a selected index, idx=0:

1. Find the sum of the others: sum = 50 + 25 + 24 = 99. You may want to cache these ratios until idx changes.
2. After changing L[idx], find remaining amount: remaining = 100-L[idx]
3. Adjust other values according to their proportion, with rounding: (L[jdx]*remaining)/sum.
4. Add or remove 1 to one of the other sliders to correctly account for rounding corner cases, if the sum doesn’t match 100.

Here’s a quick test in powershell:
foreach ( $z in ((50,25,24), (25,25,25)) ) {
  foreach ( $y in (0,1,50,99,100) ) {
    $remaining = 100-$y;
    $total = $z | measure -sum | select -expand sum;
    $others = $z |% {
      [Math]::floor(($_*$remaining + $total/2)/$total);
    $all = ,$y + $others;
    $sum = $all | measure -sum | select -expand sum;

    $adj = 100-$sum;
    $all[1] += $adj;
    $sum += $adj;

    "sliders=$all sum=$sum"

sliders= ? 0 ? 51 ? 25 ? 24 sum=100
sliders= ? 1 ? 50 ? 25 ? 24 sum=100
sliders= 50 ? 25 ? 13 ? 12 sum=100
sliders= 99 ? ? 1 ? ? 0 ? ? 0 sum=100
sliders=100 ? ? 0 ? ? 0 ? ? 0 sum=100

sliders= ? 0 ? 34 ? 33 ? 33 sum=100
sliders= ? 1 ? 33 ? 33 ? 33 sum=100
sliders= 50 ? 16 ? 17 ? 17 sum=100
sliders= 99 ? ? 1 ? ? 0 ? ? 0 sum=100
sliders=100 ? ? 0 ? ? 0 ? ? 0 sum=100
Edited by fastcall22

Share this post

Link to post
Share on other sites

Add or remove 1 to one of the other sliders to correctly account for rounding corner cases, if the sum doesn’t match 100.


This part could get a bit arbitrary. If you had {25,25,25,25} and increased one of them by 1, where do you take the 1 from?


I mean you could pick an arbitrary (even random) solution, but I'm wondering about the use case here. Could you just use floats?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement