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 Peewee · Feb 23, 2013 at 11:19 PM · power

Starship power core help needed please.

Hi everyone,

I need a little help with a scripting problem. I have been searching for answers on the forums and here but with little luck.

What i'm attempting to do is create a Power source system for example a starship has a power core which produces X amount of total power and then ship system's draw power from the power grid which drains power from the powercore and then be able to display this information on a computer console in game that the player can access to adjust power settings depending on the situation.

As i understanding it (I am rather new to scripting but slowly getting there :) i'll need a script that controls the power core itself and a script that represents various power nodes around the ship (think of a star trek ship you have the warp core and the power grid with various eps junctions through out the ship) and then a script which can be used for the various ships systems (life support, lights, engines, weapons, shields etc)

If anyone can point me in the right direction i would be grateful.

Thanks Pete

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiloblargh · Feb 24, 2013 at 12:15 AM

That's very easy to do, and you don't need more than one script. It just comes down to arithmetic.

Have the max power consumption of each of the systems as a variable. Then multiply each by what percent of capacity it is currently running at. Add them all up. Subtract the total from the generator output multiplied by what percent of its capacity it is running at. Got a positive number? Great, all systems go. No? Then scale down the power available to each system by the ratio of what you've got to what you need.

For weapons, they should charge up. The bigger the guns and the faster they charge, the more power they will use, and when they are done charging, they don't consume any more power until they are fired.

Using InvokeRepeating can just add some amount to the "weapon battery" variable a few times a second until it reaches the maximum value, then CancelInvoke on that, set the "charge weapon" system's draw to 0, and then either wait for the player to fire or automatically fire, then you turn back on the charge weapon system.

fwiw, if I were designing a starship, I wouldn't make the power distribution something that needs to be manually controlled; it should adapt automatically to circumstances (more scripting...) until you override it.

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
avatar image
0

Answer by Peewee · Feb 24, 2013 at 12:49 AM

Thanks for your answer Kilo,

Below is the script as it sits atm it displays what will be my ships power bar on screen but i'm lost as to what to do now. For example say i want life support to use 5% of available power and display that on screen? Is there any script examples you know of that would help me to understand how to impalement that?

Thanks Pete

 using UnityEngine;
 using System.Collections;
 
 public class Warpcore : MonoBehaviour {
     public int maxPower = 100;
     public int curPower = 100;
     
     public float PowerBarLength;
     
     
 
     // Use this for initialization
     void Start () {
         PowerBarLength = Screen.width / 3;
     
     }
     
     // Update is called once per frame
     void Update () {
         AdjustCurrentPower(0);
     
     }
     
     void OnGUI(){
         GUI.Box(new Rect(10, 590, PowerBarLength, 20), curPower + "/" + maxPower);
     }
     
     public void AdjustCurrentPower(int adj){
         curPower += adj;
         
         if(curPower < 0)
             curPower =0;
         
         if(curPower > maxPower)
             curPower = maxPower;
         
         if (maxPower < 1)
             maxPower = 1;
         
         PowerBarLength = (Screen.width / 3) *(curPower / (float)maxPower);
     }
 }
 
Comment
Add comment · Show 3 · 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 Kiloblargh · Feb 24, 2013 at 07:51 AM 0
Share

Sure. Just duplicate the power bar object you've already done and after you set PowerBarLength, you can say LSBarLength = (PowerBarLength * .05). Easy peasy pumpkinsqueezy. You should probably declare curPower and maxPower as floats rather than ints. I personally dislike OnGUI so if I were making this, would simply use a scaled cube parented to the camera with 3dText for the labels.

avatar image Kiloblargh · Feb 24, 2013 at 08:25 AM 0
Share

Actually I think your main problem is that you need to take a step back and not worry about the script yet; just close Unity, open a blank text document and write down in plain English everything that you're intending to do. Then break it into smaller and smaller problems of what needs to happen to accomplish that. Don't try to design your game in $$anonymous$$onoDevelop as you go, you'll paint yourself into a corner and sooner or later have to redo everything from scratch anyway.

avatar image Peewee · Feb 24, 2013 at 02:41 PM 0
Share

Thank you for your advise i do have a design document from which i am working from and it seems constantly adding to as new ideas hit me. What i'm working on is more of a prove of concept then a full fleshed out game.

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

9 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 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