Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 09jgriffin · Oct 25, 2011 at 12:14 PM · guiitemsstrategyresource

Resource Script

Hi i'am not very good at programming but i get there eventually but i can't seem to find a script which does what i would like it to do

Basacilly i'am trying to make a strategy game and i'am stuck on how to generate resources and make it displayed on a GUI so any help would be appracited :)

Comment
Add comment · Show 6
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 syclamoth · Oct 25, 2011 at 10:37 AM 0
Share

Resources are just a float value! (or a double, or an int, depending on how you want them to work) You can keep track of it in some 'GameEngine' class, and then query that from your GUI script to show them on the screen.

avatar image 09jgriffin · Oct 25, 2011 at 10:51 AM 0
Share

um how would you do that exactly??

avatar image syclamoth · Oct 25, 2011 at 11:19 AM 0
Share

How much of your game have you done already? You can't just start with resources, have you got unit production in yet? I can't really design your game for you, presumably you have a method in $$anonymous$$d for resource gathering!

avatar image 09jgriffin · Oct 25, 2011 at 12:51 PM 0
Share

Well basically i have made the terrain made the soldier's follow my mouse and all i there is only one major thing left which is the Resources and i would like something like every 10 seconds it gives me 50 wood/Gold/Iron/Stone that sort of thing

avatar image Tseng · Oct 25, 2011 at 03:42 PM 0
Share

Sorry, if you don't know such basic program$$anonymous$$g/scripting at all, you should give up on making games and get a programmer who does program$$anonymous$$g for you while you do the art or whatever else.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by save · Oct 25, 2011 at 01:26 PM

Your description is very vague as this can be done in a million ways. Make a plan for how this should be achieved, sketch it up on a mindmap where you can see the steps.

First you need to consider how resources are measured, does the player get more resources by owning land/mines/farms in quantity? Is the achievement of harvest done graphical so a lumberjack carries the wood into a house?

You'd then first need to make a system for each harvesting item, that could be as simple as a couple of int values. The player has 2 goldmines which means that every 10 seconds you'll receive 50*2 gold. You'll need to decide if this is done automatically or done by actual GameObject traveling from harvesting to central warehouse (like done in Warcraft 1/2). If so then you'd set up something like when the GameObject enters a certain area there's a trigger-function that adds onto an int which is displayed on the GUI.

Displaying something on the GUI is pretty straight forward,

static var goldMines : int = 1; static var goldAmount : int = 0;

function OnGUI () { GUI.Label (Rect (10, 10, 60, 20), goldAmount.ToString()); }

So, set up a manager (empty GameObject with a script) which doesn't destroy on load if you have several levels where the player progress together with collected items. On that item make sure you have static variables which can be reached from another script.

resourceManager.goldAmount += 50*resourceManager.goldMines;

There's not so much else to it actually, good luck!

Comment
Add comment · Show 13 · Share
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 09jgriffin · Oct 25, 2011 at 02:12 PM 0
Share

is this included in the other script? (resource$$anonymous$$anager.goldAmount += 50*resource$$anonymous$$anager.gold$$anonymous$$ines;)

also it came up with an error saying that it didn't know what resource$$anonymous$$anager means

avatar image syclamoth · Oct 25, 2011 at 02:38 PM 0
Share

You need to write your own resource$$anonymous$$anager. This stuff doesn't happen through magic, you know.

avatar image 09jgriffin · Oct 25, 2011 at 03:02 PM 0
Share

I know but what is a resource $$anonymous$$anager?

avatar image save · Oct 25, 2011 at 03:05 PM 0
Share

$$anonymous$$ake a script called resource$$anonymous$$anager and put it on a GameObject. ;-)

avatar image 09jgriffin · Oct 25, 2011 at 03:08 PM 0
Share

can it be empty for does it need to have code in it?

Show more comments
avatar image
0

Answer by RayDaX · Aug 03, 2013 at 09:12 AM

Here is a simple script i made to get resources calculated as a float value and in GUI it is added as a int to get rid of decimals.All you need to change is the Production amount / hour and updatetime for how often you want the data to update in seconds.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerData : MonoBehaviour {
     
     /*
      * PlayerGold holds the gold amount in a float.
      */
     public float PlayerGold = 0.0f;
     
     /*
      * Gold production is calculated like this:
      * 
      * 100 Gold / Hour
      * 
      * Take 100 divided by 3600 seconds (3600 seconds = 1 hour) U get a value (0.0277777777777778)
      */
     public float GoldProduction = 0.0277777777777778f;
     
     /*
      * UpdateTime is how often you want your Gold value updated in seconds.
      */
     public float UpdateTime = 10.0f; 
     
     
     
     // Use this for initialization
     void Start () {
         InvokeRepeating ("IncreaseResources", UpdateTime, UpdateTime);
         
     }
     
     void IncreaseResources() {
         PlayerGold += GoldProduction * UpdateTime;
         
     }
     
     void OnGUI(){
         GUI.Label(new Rect(100,100,100,25),"Gold: "+PlayerGold);
     
         
     }
 }
 
Comment
Add comment · Share
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

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

7 People are following this question.

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

Related Questions

Examples of TBS/Heavily Gui-driven Games in Unity? 2 Answers

Adding 1 point after collison 1 Answer

How To Make A Numeric Inventory System? 0 Answers

how can i collect items that fills up a GUI?? 1 Answer

How to set up a gui text box to count inventory items? 1 Answer


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