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 femi96 · Mar 06, 2012 at 11:27 PM · speedrpgturnunits

RPG Stat Based Turn System

Main Question How do I make one script reference and compare the values of variables in another script on multiple game objects?

Info I'm working on an RPG similar to Final Fantasy Tactics or Final Fantasy Tactics A2. I have the main cursor movement and maps done, but I still need to fix the unit system. The problem is I need a turn system that compares the speed values of all units, and makes the highest one go first, and I have no clue how to do this. If anyone could help me, it would be greatly appreciated.

What I Have:

Stats:

 var maxHP = 10;
 var maxMP = 10;
 
 var str = 10;
 var end = 10;
 var prc = 10;
 var wis = 10;
 var res = 10;
 var spd = 10;
 var acc = 10;
 
 var move = 5;
 var jump = 2;
 
 var curHP : int;
 var curMP : int;
 
 var redBox : GUIStyle;
 var blueBox : GUIStyle;
 var word : GUIStyle;
 
 private var nextMove : float = 0.0;
 
 function Start ()
 {
   curHP = maxHP;
   curMP = maxMP;
 }
 function OnGUI ()
 {
   var hit : RaycastHit;
   var layerMask = 1 << 9;
   if (Physics.Raycast ((Vector3(0,-1,0) + transform.position), Vector3.one, hit, 1, layerMask))
   {
     GUI.Box (Rect (10,Screen.height-40,(Screen.width * curHP)/(2 * maxHP),20),"",redBox);
     GUI.Box (Rect (10,Screen.height-70,(Screen.width * curMP)/(2 * maxMP),20),"",blueBox);
     GUI.Box (Rect (10,Screen.height-40,(Screen.width/2),20), curHP+ "/" +maxHP, word);
     GUI.Box (Rect (10,Screen.height-70,(Screen.width/2),20), curMP+ "/" +maxMP, word);
     GUI.Box (Rect (10,Screen.height-85,(Screen.width/2),80), "");
   }
 
   if (curHP < 0)
   curHP = 0;
   if (curMP < 0)
   curMP = 0;
 
   if (curHP > 0)
   curHP = maxHP;
   if (curMP > 0)
   curMP = maxMP;
 }

Turn System(This is my problem):

  //place >> turn start > units > turn end
     //  turn start - start of turn
     //  units - use units for movement, attack, and defence
     //  turn end - resets speed value and returns to start
     function Start ()
     {
       BroadcastMessage("Place");
     }
     
     function Place ()
     {
       BroadcastMessage("Turn");
     }
     
     function Turn ()
     {
       var tem : Stats;
       tem = gameObject.GetComponentInChildren(Stats);
     }
     
     function Update ()
     {
     
     }

I figured out how by myself...

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by rutter · Mar 14, 2012 at 02:39 AM

This is potentially a very large and complicated system you're describing. You might try starting with something smaller as a learning project.

Either way, my advice is about the same: consider each piece of your system. What does it do? What information does it need to do that? What systems can you build to provide data, functionality, and support?

It's useful to consider both frontend and backend: how will your player interact with the system, and how will those interactions affect the internal state of your game? Maybe you need a data structure to represent the player's current equipment. If so, what values should you store in it?

For example, let's say you want the player to equip a weapon. Perhaps you need a menu for that. Once the weapon is equipped, the player's attacks should be more effective (maybe they hit more often, or deal more damage). How can your game's programming represent that? What other values should affect the player's attacks?

Once you've defined the pieces of your system, building it should be more straightforward. Break your big problem into smaller ones that are easier to solve.

If you want a more specific answer, you'll need to ask a more specific question.

Comment
Add comment · Show 4 · 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 Berenger · Mar 14, 2012 at 02:47 AM 0
Share

I agree with rutter. The best advice I can give is try to picture how everything is going to work once it's done. Think of what is going to interact with what, what's going to be problematic, how to solve it etc, BEFORE you start coding. Then, do it step by step, no rush.

I'm currently working of something very similar. If you need inspiration, here is an example of what I came up with. No idea what it's worth so be careful :p

avatar image femi96 · Mar 14, 2012 at 10:57 PM 0
Share

I updated it with the coding I have for it. The main problem is linking the stats of all units to the turn system to compare their speed values. From there I shouldn't have any problems.

avatar image Kleptomaniac · Mar 18, 2012 at 03:46 AM 0
Share

You'll need to format your code properly. Highlight all of the code and then press the 101010 button in the toolbar.

avatar image femi96 · Mar 22, 2012 at 12:45 AM 0
Share

Code properly formatted, question specified, anything else?

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Melee combat error 1 Answer

Getting XP Script Help 2 Answers

rts developement 0 Answers

How can i have 3 weapon to switch between?? 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