- Home /
Souls pickup mechanic
Hey guys I have been struggling with implementing this mechanic. I am making a metroidvania and I am implementing a souls mechanic to the game. I know what needs done I am just having trouble implementing it.
When they die they will go back to a previous shrine
The player willdrop their Nexa Stones
Then make it so when the player dies they lose the stock of nexa stones (or maybe a hollow knight mechanic with the wandering spirit?)
Add a respawn timer so it feels natural ( do that after you get
intial death state working)Create a Respawn function that will work similar to the start
function. This is important because
everything needs to be reset when the player is killed.Need to link the nexa stone functionality to death so when the
player dies they drop the nexa stone and then they can go back and get the lost stones. If they die again those stones are gone for goodAfter this has all been implemented this will be working
as desired.
So here is the code that I have now
void DeathState()
{
isDead = true;
if(isDead == true)
{
int randIndex = UnityEngine.Random.Range(0, PickupTypes.Length);
Instantiate(PickupTypes[randIndex], transform.position, transform.rotation);
player.SetActive(false);
nexaStones.CurrentVal = nexaStones.CurrentVal;
Respawn();
}
}
public void Respawn()
{
health.CurrentVal = 100;
spiritEnergy.CurrentVal = 100;
//nexaStones.CurrentVal = 0;
facingRight = true;
inWolfForm = false;
canAlphaCommand = true;
wolfSense = false;
isDead = false;
player.transform.position = respawnLocation.transform.position;
player.SetActive(true);
SetState(PlayerStates.IDLE);
}
Here are the scripts for my HUD elements as well cause I know thats important (i got this from a youtube tutorial from inScopeStudious)
[Serializable] public class Stat { [SerializeField] private BarScript bar;
[SerializeField]
private float maxVal;
[SerializeField]
private float currentVal;
public float CurrentVal
//Set the current Value with this one
{
get
{
return currentVal;
}
set
{
this.currentVal = Mathf.Clamp(value,0,MaxVal);
bar.Value = currentVal;
}
}
public float MaxVal
{
get
{
return maxVal;
}
set
{
this.maxVal = value;
bar.MaxValue = maxVal;
}
}
public void Initialize() { this.MaxVal = maxVal; this.CurrentVal = currentVal; }
} public class BarScript : MonoBehaviour {
private float fillAmount;
[SerializeField]
private float lerpSpeed;
[SerializeField]
private Image content;
[SerializeField]
private Text valueText;
[SerializeField]
private Color fullColor;
[SerializeField]
private Color lowColor;
[SerializeField]
private bool lerpColors;
public float MaxValue { get; set; }
public float Value
{
set
{
string[] tmp = valueText.text.Split(':');
valueText.text = tmp[0] + ": " + value;
fillAmount = Map(value, 0, MaxValue, 0, 1);
}
}
// Use this for initialization
void Start ()
{
if(lerpColors)
{
content.color = fullColor;
}
}
// Update is called once per frame
void Update ()
{
HandleBar();
}
private void HandleBar()
{
if(fillAmount != content.fillAmount)
{
content.fillAmount = Mathf.Lerp(content.fillAmount,fillAmount, Time.deltaTime * lerpSpeed);
}
if(lerpColors)
{
content.color = Color.Lerp(lowColor, fullColor, fillAmount);
}
}
private float Map(float value, float inMin, float inMax, float outMin, float outMax)
{
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
//(80 - 0) * (1 - 0) / (100 - 0) + 0
// 80 * 1 / 100 + 0 = 0.8;
}
}
If anyone can help me out point me in the right direction it would be lovely if you need more explaining I will do my best.
Kindly,
Harpoaian
Your post is a list of tasks, not really a question. If you want help, split this into 6 concise and sincere questions (ended with a "?").
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can't get platforming character to jump 2 Answers
Any way to completely learn to script in C# using Unity? 3 Answers
Jumping is randomly not working. 0 Answers