Closed utterances-bot closed 4 years ago
Currently working on this now
itch.io --> inscope.me --> assets: 2.0 RPG
Changed: Scene:
Canvas:
Portrait Frame:
Added Scripts:
It's looking good - currently at 19.06 at http://youtube.com/watch?v=8StwNBJ5fE8&t=1906s
Commit: https://github.com/IrisDroidology/manacaster/commit/86dd4ff57aa2ea7e509b14bfcd75e1f9cf4829e6
Starting to work through this again now!
Commit: https://github.com/IrisDroidology/manacaster/commit/5d1dc8fa556473df6791f350694e3d7d60e97661
Setting the health manually in player.cs
:
health.MyCurrentValue = 10000; // health game object in scene: Scene
This bit was missing:
set{
if (value > MyMaxValue)
{
currentValue = MyMaxValue;
}
Assets/Scripts/Stat.cs
@ line 22
After doing this, this line can be removed//commented:
// currentValue = value; // Value (RHS) set in player.cs
currentValue = value; // Value (RHS) set in player.cs
Preventing negative values @ 20:44
set{
if (value > MyMaxValue)
{
currentValue = MyMaxValue;
}
else if (value < 0)
{
currentValue = 0;
} // Line 22 --> see above
Then this needs to be added:
else if (value < 0)
{
currentValue = 0;
}
else
{
currentValue = value;
}
After adding this, setting the player health to a value between 0-100 (for example 10):,
health.MyCurrentValue = 10;
...results in no problems
stat.cs
so that values can be set:
// Initialize for stat values // Line 55
public void Initialize(float currentValue, float maxValue)
{
MyMaxValue = maxValue;
MyMaxValue = currentValue;
}
Then we need to add this to the player.cs
script & character.cs
script:
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
}
This becomes:
// Use this for initialization
protected virtual void Start () {
animator = GetComponent<Animator>();
}
Player.cs
Script for Number on this issue comment:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This is the player script, it contains functionality that is specific to the Player
/// </summary>
public class Player : Character
{
[SerializeField]
private Stat health;
[SerializeField]
private float healthValue;
[SerializeField]
private float maxHealth;
protected override void Start()
{
health.Initialize(health, maxHealth); // Was 100, 100
base.Start();
}
........
Becomes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This is the player script, it contains functionality that is specific to the Player
/// </summary>
public class Player : Character
{
[SerializeField]
private Stat health;
//[SerializeField]
//private float healthValue;
[SerializeField]
private float maxHealth;
protected override void Start()
{
health.Initialize(maxHealth, maxHealth); // Was 100, 100 // healthValue, maxHealth);
base.Start();
}
Currently at 27.37
Commit: https://github.com/IrisDroidology/manacaster/commit/2c6966dc9b71626911b47add1942953f4c5a27da, https://github.com/IrisDroidology/manacaster/commit/58723bb427a8fd2d0968ca16cead93f0e69d3539
For debugging:
Press "O" to add 10 health to player game object, press "I" to do opposite:
//Player.cs
/// <summary>
/// We are overriding the characters update function, so that we can execute our own functions
/// </summary>
protected override void Update ()
{
//Executes the GetInput function
GetInput();
base.Update();
}
/// <summary>
/// Listen's to the players input
/// </summary>
private void GetInput()
{
direction = Vector2.zero;
// Debugging - inscope.me RPG 2.0
if (Input.GetKeyDown(KeyCode.I))
{
health.MyCurrentValue -= 10 // Lose 10 health - player game object
}
if Input.GetKeyDown(KeyCode.O)
{
health.MyCurrentValue += 10 // Add 10 health (see above ^^) - healing debug function
}
........
{
direction = Vector2.zero;
// Debugging - inscope.me RPG 2.0
if (Input.GetKeyDown(KeyCode.I));
{
health.MyCurrentValue -= 10; // Lose 10 health - player game object
}
if (Input.GetKeyDown(KeyCode.O));
{
health.MyCurrentValue += 10; // Add 10 health (see above ^^) - healing debug function
}
Smooth transitions for bar fill changes:
[SerializeField]
private float lerpSpeed;
........
// Update is called once per frame
void Update()
{
if (currentFill != content.fillAmount){
content.fillAmount = Mathf.Lerp(content.fillAmount,currentFill, Time.deltaTime * lerpSpeed) // Moves equally on every single device // Smooth transitions
}
Then I set the "lerpSpeed" in "health" game object to 0.5 Same thing also with mana in scene: "scene"
Then we need to set up the "Mana" game object ^^:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This is the player script, it contains functionality that is specific to the Player
/// </summary>
public class Player : Character
{
[SerializeField]
private Stat health;
[SerializeField]
private Stat mana;
//[SerializeField]
//private float healthValue;
// [SerializeField]
private float initHealth = 100;
private float initMana = 50;
protected override void Start()
{
health.Initialize(initHealth, initHealth); // Was 100, 100 // healthValue, maxHealth);
mana.Initialize(initMana, initMana);
base.Start();
}
...
private void GetInput()
{
direction = Vector2.zero;
// Debugging - inscope.me RPG 2.0
if (Input.GetKeyDown(KeyCode.I));
{
health.MyCurrentValue -= 10; // Lose 10 health - player game object
mana.MyCurrentValue -= 10;
}
if (Input.GetKeyDown(KeyCode.O));
{
health.MyCurrentValue += 10; // Add 10 health (see above ^^) - healing debug function
mana.MyCurrentValue += 10; // ^^
}
After doing this, I think I know what the error was with Issue #7 on Github/Acord-Robotics/Manacaster: see 33.52 in the video
BTW, quick note: sometimes these codesnippets have the file names added at the top line of the snippet, go to the github issue and click edit on the comment to see them.
We can now close this issue, as it is done!
Health & Mana Bars | Stellarios
Creating Health & Mana Bars for Manacaster Unity
https://acord-robotics.github.io//stellarios/ar-11-healthmanabar2dot0/