Post: [C#] Need some help with effecting something with time
10-05-2015, 01:59 PM #1
ModaTron
Are you high?
(adsbygoogle = window.adsbygoogle || []).push({}); Im trying to subtract 1 from my health after a specific amount of time and having trouble implementing this. im trying to use Time.deltaTime but im SUPER novice at C# and cant really get it.

can you help me out and explain why it works? thanks!

using UnityEngine;
using System.Collections;


public class PlayerHealth : MonoBehaviour
{


public int maxHealth = 100;
public int curHealth = 100;
public float subtractHealth = -1f;


public float healthBarLength;

// Use this for initialization
void Start()
{
healthBarLength = Screen.width / 3;
}

// Update is called once per frame
void Update()
{
AdjustCurrentHealth (0);
}

void OnGUI()
{

GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);


}


public void AdjustCurrentHealth(int adj)
{
curHealth += adj;

if (curHealth < 0)
curHealth = 0;

if (curHealth > maxHealth)
curHealth = maxHealth;

if (maxHealth < 1)
maxHealth = 1;

healthBarLength = (Screen.width / 3) * (curHealth / (float)maxHealth);


}
}
10-07-2015, 06:14 PM #2
Winter
Purple God
So I had something wrote out, then I noticed that you said "can you help me out and explain why it works?", do you want to know how it works or how to implement it? I assume you're using Unity.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo