- Home /
Gas Fuel Implementation
Im a beginner with scripts and i need to implement gas fuel into this game. Below is a screenshot of the scene and how it looks. Basically there is 8 fuel bars and each bar holds 10 fuel ( its not exactly 10 fuel, the fuel will be determined by referencing the game object but 10 is an example) which is a total amount of 80 . Also if the player decides to click the refuel button, they get some fuel back. I guess my issue with this i seem to have a hard time connecting the scene and script together. Any tips or feed back would be nice and below is the code and image of the UI. Thank you.
public class GamePlayScene : MonoBehaviour
{
// Start is called before the first frame update
public Image[] FuelCarts = new Image[8];
public GameObject gameController;
Random rand = new Random();
public int MaxFuel = 80; //The number will come from gamecontroller
public int FuelWasted = rnd(1, 20);
public int currentFuel;
void Start()
{
/*
*Current Fuel
*
*
*/
}
void Update() { }
void refuel()
{
currentFuel = currentFuel + rand(1, 15);
}
}
Could you give some more specific detail about what you really want to do?
Well this is a multiplayer game (not online, tabletop game). So each player will have a set amount of fuel at the start of the match. So once a player is in the scene ( in the screenshot) they will click a track (1 of those white 6 boxes) and then after traveling to those tracks they will lose a random amount of gas. Also they could refuel but clicking the refuel button.
You can attach the script to the button and use either void On$$anonymous$$ouseDown()
or a UnityEvent in void refuel()
you can also get rid of void Update() { }
if you're not using it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612194522im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to find UI in code c# (button, Panel etc) 2 Answers
Need help on gas fuel implementation ( Beginner) 0 Answers
how to deal with GameObject class and my custom inheritance 1 Answer
How to double spirte/gameobject/prefab and control the result on those items? 0 Answers
If a script is attached to more than one gameObject, will Start() & Awake() run more than once? 2 Answers