r/Unity3D – Telegram
r/Unity3D
259 subscribers
12.6K photos
15.5K videos
14 files
47.8K links
News about the Unity engine and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).
Download Telegram
Media is too big
VIEW IN TELEGRAM
I got bored and made a third person character like in Resident Evil games

https://redd.it/1k7vcr0
@r_Unity3D
Stamina Bar

I started learning Unity yesterday and I'm working on implementing a stamina bar to my project. Here is a link to a video of what I have so far. Code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;



public class PlayerMovement : MonoBehaviour

{

// Start is called before the first frame update



public float moveSpeed;

public Rigidbody2D rb;

private Vector2 moveDirection;





[SerializeField] private TrailRenderer tr;



[SerializeField] float dashSpeed = 10f;

[SerializeField] float dashDuration = 1f;

[SerializeField] float dashCooldown = 1f;

[SerializeField] bool isDashing = false;



public Image StaminaBar;

public float stamina, maxStamina;

public float dashCost;

public bool canDash;



private float chargeRate;

private Coroutine recharge;





// Update is called once per frame

void Update()

{



if (isDashing)

{

return;

}

ProcessInputs();

if (Input.GetKeyDown(KeyCode.Space))

{

StartCoroutine(Dash());

}





}

private void FixedUpdate()

{

if (isDashing)

{

return;

}



Move();

}

void ProcessInputs()

{

float movex = Input.GetAxisRaw("Horizontal");

float movey = Input.GetAxisRaw("Vertical");

moveDirection = new Vector2(movex, movey).normalized;

}

private void Move()

{



rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);

}

private IEnumerator Dash()

{

isDashing = true;

stamina -= dashCost;

if(stamina < 0)

stamina = 0;

StaminaBar.fillAmount = stamina / maxStamina;

rb.velocity = new Vector2(moveDirection.x * dashSpeed, moveDirection.y * dashSpeed);

tr.emitting = true;

yield return new WaitForSeconds(dashDuration);

tr.emitting = false;

isDashing = false;

if (recharge != null)

{

StopCoroutine(recharge);

recharge = StartCoroutine(RechargeStamina());

}

}

private IEnumerator RechargeStamina()

{

yield return new WaitForSeconds(1f);

while(stamina < maxStamina)

{

stamina += chargeRate / 10f;

if(stamina > maxStamina)

stamina = maxStamina;

StaminaBar.fillAmount = stamina / maxStamina;

yield return new WaitForSeconds(.1f);

}

}

}

As you can see in the video, the player dashes correctly, and stamina is drained, but it doesn't refill. I feel like I'm missing something obvious but idk what.

https://redd.it/1k80kp6
@r_Unity3D
what do you think of this art style?
https://redd.it/1k85dfn
@r_Unity3D
Media is too big
VIEW IN TELEGRAM
I made a breakdown video of the melee aim assist + animation overide setup in my game

https://redd.it/1k86dps
@r_Unity3D