Topic: [Tutorial] Basic Score Counter
Hello
I made a short tutorial, how to create a very simple score-counter in your UFE-game.
Video-Tutorial:
[media]https://www.youtube.com/watch?v=ad4l4TUofA4[/media]
Code Snippets:
UFE Score Code
==============
1. Assets > UFE > Scripts > UFE.CS
-------------------------------------------------------------------------------
after (line 83):
public static GUIText debugger1;
public static GUIText debugger2;
insert:
//*** Global Score Counter ***
public static int scorePlayerOne = 0;
public static int scorePlayerTwo = 0;
2. Assets > UFE > Scripts > ControlsScript.cs
-------------------------------------------------------------------------------
after (line 1959):
comboHitDamage = damage;
comboDamage += damage;
comboHits ++;
insert:
//*** increase Score if the opponent takes any damage ***
if (gameObject.name == "Player1" && damage > 0)
{
UFE.scorePlayerTwo = UFE.scorePlayerTwo + hit.scoreOnHit;
}
if (gameObject.name == "Player2" && damage > 0)
{
UFE.scorePlayerOne = UFE.scorePlayerOne + hit.scoreOnHit;
}
3. Assets > UFE > Scripts > UI > Templates > DefaultBattleGUI.cs
-------------------------------------------------------------------------------
after (line 12):
public Image lifeBar;
public Image gaugeMeter;
insert:
public Text score;
after (line 177):
if (this.player2GUI != null && this.player2GUI.gaugeMeter != null)
{
this.player2GUI.gaugeMeter.fillAmount = UFE.config.player2Character.currentGaugePoints / UFE.config.player2Character.maxGaugePoints;
}
}
insert:
//*** feed the Battle-GUI with current scores for player 1/2 ***
if (this.player1GUI.score != null)
{
this.player1GUI.score.text = "P1 " + String.Format ("{0:00000000}", UFE.scorePlayerOne);
}
if (this.player2GUI.score != null)
{
if (UFE.GetCPU (2) == false) this.player2GUI.score.text = "P2 " + String.Format ("{0:00000000}", UFE.scorePlayerTwo);
else this.player2GUI.score.text = "CPU";
}
4. Assets > UFE > Editor > MoveEditorWindow.cs
-------------------------------------------------------------------------------
after (line 675):
// Damage Toggle
moveInfo.hits[i].damageOptionsToggle = EditorGUILayout.Foldout(moveInfo.hits[i].damageOptionsToggle, "Damage Options", EditorStyles.foldout);
if (moveInfo.hits[i].damageOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.hits[i].damageType = (DamageType) EditorGUILayout.EnumPopup("Damage Type:", moveInfo.hits[i].damageType, enumStyle);
moveInfo.hits[i].damageOnHit = EditorGUILayout.FloatField("Damage on Hit:", moveInfo.hits[i].damageOnHit);
moveInfo.hits[i].damageOnBlock = EditorGUILayout.FloatField("Damage on Block:", moveInfo.hits[i].damageOnBlock);
moveInfo.hits[i].damageScaling = EditorGUILayout.Toggle("Damage Scaling", moveInfo.hits[i].damageScaling, toggleStyle);
moveInfo.hits[i].doesntKill = EditorGUILayout.Toggle("Hit Doesn't Kill", moveInfo.hits[i].doesntKill, toggleStyle);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}
insert:
//*** Score Toggle ***
moveInfo.hits[i].scoreOptionsToggle = EditorGUILayout.Foldout(moveInfo.hits[i].scoreOptionsToggle, "Score Options", EditorStyles.foldout);
if (moveInfo.hits[i].scoreOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.hits[i].scoreOnHit = EditorGUILayout.IntField("Score on Hit:", moveInfo.hits[i].scoreOnHit);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}
after (line 2162):
// Damage Toggle
moveInfo.projectiles[i].damageOptionsToggle = EditorGUILayout.Foldout(moveInfo.projectiles[i].damageOptionsToggle, "Damage Options", EditorStyles.foldout);
if (moveInfo.projectiles[i].damageOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.projectiles[i].damageType = (DamageType) EditorGUILayout.EnumPopup("Damage Type:", moveInfo.projectiles[i].damageType, enumStyle);
moveInfo.projectiles[i].damageOnHit = EditorGUILayout.FloatField("Damage on Hit:", moveInfo.projectiles[i].damageOnHit);
moveInfo.projectiles[i].damageOnBlock = EditorGUILayout.FloatField("Damage on Block:", moveInfo.projectiles[i].damageOnBlock);
moveInfo.projectiles[i].damageScaling = EditorGUILayout.Toggle("Damage Scaling", moveInfo.projectiles[i].damageScaling, toggleStyle);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}
insert:
//*** Score Toggle ***
moveInfo.projectiles[i].scoreOptionsToggle = EditorGUILayout.Foldout(moveInfo.projectiles[i].scoreOptionsToggle, "Score Options", EditorStyles.foldout);
if (moveInfo.projectiles[i].scoreOptionsToggle)
{
EditorGUILayout.BeginVertical(subGroupStyle);
{
EditorGUI.indentLevel += 1;
moveInfo.projectiles[i].scoreOnHit = EditorGUILayout.IntField("Score on Hit:", moveInfo.projectiles[i].scoreOnHit);
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.EndVertical();
}
5. Assets > UFE > Scripts > MoveInfo.cs
-------------------------------------------------------------------------------
public class Projectile (line 238):
after (line 278):
public float damageOnHit;
public float damageOnBlock;
public bool damageScaling;
insert:
public int scoreOnHit;
after (line 293):
[HideInInspector] public bool moveLinksToggle;
[HideInInspector] public bool damageOptionsToggle;
insert:
[HideInInspector] public bool scoreOptionsToggle;
public class Hit (line 343):
after (line 369):
public bool damageScaling;
public DamageType damageType;
public float damageOnHit;
insert:
public int scoreOnHit;
after (line 386):
[HideInInspector] public bool damageOptionsToggle;
insert
[HideInInspector] public bool scoreOptionsToggle;
5. Assets > UFE > Scripts > ProjectileMoveScript.cs
------------------------------------------------------------------------------
after (line 88):
hit.damageScaling = data.damageScaling;
hit.damageType = data.damageType;
insert:
hit.scoreOnHit = data.scoreOnHit;
6. Assets > UFE > UI > Templates > DefaultMainMenuScreen.cs
-------------------------------------------------------------------------------
after (line 26):
base.OnShow ();
this.HighlightOption(this.FindFirstSelectable());
insert:
//*** reset player score when entering main menu ***
UFE.scorePlayerOne = 0;
UFE.scorePlayerTwo = 0;
Copy & paste the code-snippets in a new text-file with your editor.