ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 27, 2015 0:07:46 GMT
I just got your 2 asset and they look great  , How do i Access, Display or Save WorldVariables (Health, Score etc) , for example using the new UI Text to display the values in C# in a different script ? I tried this bout was getting error " error CS0029: Cannot implicitly convert type `InGameWorldVariable' to `int' "
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TestScript : MonoBehaviour {
public Text textDisplay;
public int scoreVar;
// Update is called once per frame
void Update () {
scoreVar = WorldVariableTracker.GetWorldVariable("Score");
textDisplay.text= "" + scoreVar;
}
}
Thank you.
|
|
|
Post by DarkTonic Dev on Mar 27, 2015 3:25:43 GMT
You're missing need a ".CurrentFloatValue" or ".CurrentIntValue", depending on variable type, like this:
textDisplay.text = "" + scoreVar.CurrentIntValue;
However, we've included scripts to do this automatically: WorldVariableListener.cs. Try those!
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 27, 2015 10:04:27 GMT
You're missing need a ".CurrentFloatValue" or ".CurrentIntValue", depending on variable type, like this: textDisplay.text = "" + scoreVar.CurrentIntValue;
However, we've included scripts to do this automatically: WorldVariableListener.cs. Try those! The ".CurrentFloatValue" or ".CurrentIntValue" don't work and found the WorldVariableListener.cs with the UI example scene but i still don't understand how to give score or experience from an achievement system, when a player picks up an item and also connecting it to an inventory system. And i also have a charater selection scene before the game starts. Do you have video i can look at please? Sorry about this, am making a 3d adventure game and its first time trying to make a game so just try to understand all these.
|
|
|
Post by DarkTonic Dev on Mar 27, 2015 16:33:22 GMT
What do you mean they don't work? Are you getting errors?
Watch the Killable video for examples of how to award XP. There's a stickied post in this forum with all the videos.
Also see Example Scene 2: Triggered Spawners for awarding Score. Each Killable has "World Variable Modifiers" sections for this.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 27, 2015 20:47:44 GMT
Yes i was, i will take a look at them ty.
|
|
|
Post by DarkTonic Dev on Mar 27, 2015 23:30:31 GMT
No problem.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 28, 2015 14:22:48 GMT
I look at the example and i understand a bit more, but what i don't still understand is, in my game i have a script for a health bar how do i send information from the WorldVariable (Health) when the player get damage or gain health the health bar reduce or increase.
In the UI example you can gain XP, if i have a script that displays a XP bar how do i send the XP gained to that bar to add up.
I also got the Easy Save 2, if i can save the WorldVariable name and value from the WorldVariableListener that way i can call it in another script to add or subtract etc?
This asset its great but its not easy trying to get it to work with my project but will keep trying.
|
|
|
Post by DarkTonic Dev on Mar 28, 2015 17:55:17 GMT
1) A World Variable Listener script automatically gets notified when the World Variable value changes. So please use a World Variable Listener. Make a subclass if you need something like a health bar. 2) Normally you add to a World Variable by just using a Killable's "Death Variable World Modifier Scenarios" section (take a look at the enemies in Example Scene 2) or watch the videos on Youtube. So you can add to a variable when something dies or gets picked up. You can use "drops" that the player picks up to gain XP or another variable with 0 Attack Points and 1 Hit Point so they don't damage the player when they pick up. 3) If you want your player to use a World Variable for Hit Points, select "Variable" (blue dropdown) for its Start Hit Points, select the variable from the dropdown, then check the box for "Sync H.P. Variable". 4) If you want to modify a World Variable by script, use code like in the readme:
var variable = WorldVariableTracker.GetWorldVariable("yourVarName"); // add 100 variable.CurrentIntValue += 100; // or CurrentFloatValue for a float!
You'll be on your own for integrating with Easy Save 2. But yes that's totally doable.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 29, 2015 16:47:36 GMT
Do you Guys plan on adding save and load ?
|
|
|
Post by DarkTonic Dev on Mar 29, 2015 18:17:07 GMT
No we do not. There are other plugins such as Easy Save that specialize in that.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 29, 2015 19:51:34 GMT
Got my health bar and few other things working 
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 29, 2015 20:31:18 GMT
I have another question how can i make the player level depend on the experience gain, e.g 100 xp = Lv 2 then for the next level, the current the next max xp to be gain is multiplied by 2 for the next xp to be gain and increase player level ? or do i have to do it separately ?
|
|
|
Post by DarkTonic Dev on Mar 29, 2015 20:47:43 GMT
You would change the "level" world variable only from a World Variable Listener on the XP variable. Then you can put your XP numbers for each level into code.
|
|
ch001
New Member
Posts: 22
Posts: 22
|
Post by ch001 on Mar 29, 2015 21:08:14 GMT
You would change the "level" world variable only from a World Variable Listener on the XP variable. Then you can put your XP numbers for each level into code. Am not exactly sure what you mean please.
|
|
|
Post by DarkTonic Dev on Mar 29, 2015 21:13:35 GMT
Make a subclass of "WorldVariableListener" and hook it up to your Experience Points world variable (drag it to Listener field). Inside the UpdateValue method of the Listener, you can add code to increase the Level (World Variable) when certain Experience Points are passed (100, 300, etc).
This will require a little bit of code.
|
|