S
S
Sergey Orobinsky2019-03-24 07:32:50
Unity
Sergey Orobinsky, 2019-03-24 07:32:50

How to make pistol logic?

there is a variable (how much in the store) and (how much in stock). and how to reload what if for exampleint ammo = 15int ammoLeft = 15

ammo = 10;
ammoLeft = 10;
therefore should be
ammo = 15;
ammoLeft = 5;
?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-03-24
@serg_orobik

total = ammo + ammoLeft;
if((float)(total/15.0) == 1.0)
{
ammo = 15;
ammoLeft = 0;
} else if((float)(total/15.0)<1.0)
{
ammo = total;
ammoLeft = 0;
}else {
 // total/15 > 1, for example ammoLeft > 15
ammo = 15;
ammoLeft = total - 15;
}

G
Griboks, 2019-03-24
@Griboks

It would be wise to make the number of stores, cartridges and cartridges in the store. Then, when reloading, simply update the cartridges and throw out the magazine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question