Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bigplayali8121 · Mar 29, 2019 at 06:42 PM · gameobjectscripting beginnerimplementation

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. alt text

 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);
      }
 }
 
screenshot.png (45.9 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mchts · Mar 30, 2019 at 06:59 AM 0
Share

Could you give some more specific detail about what you really want to do?

avatar image bigplayali8121 mchts · Mar 30, 2019 at 05:05 PM 0
Share

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.

avatar image Magso · Mar 30, 2019 at 08:28 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

154 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges