Question by
bschubert · Jan 03, 2019 at 08:27 PM ·
time.deltatimerecttransformhealthbar
how to decrement a RecctTransformed.anchoredposition by time.deltatime
i have a line of code that im trying to decrement the rectTransform.anchoredPosition.x with time.deltatime i need it to -= the x position but the argument won't accept and = sign.
thirstBarEmpty.rectTransform.anchoredPosition = new Vector2(-=0.1f*(Time.deltaTime / thirstFallRate), 0f);
if i could store x in a variable i believe it will work but i can't figure out how to store thirstBarEmpty.rectTransform.anchoredPosition.x into a variable.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerVitals : MonoBehaviour {
public GameObject gameOver;
//health variable
public UnityEngine.UI.Image healthBarEmpty;
public float fullHealth;
public float halfHealth;
public float emptyHealth;
public float healthFallRate;
public float damageRate;
//thirst variables
public UnityEngine.UI.Image thirstBarEmpty;
public float fullThirst;
public float halfThirst;
public float emptyThirst;
public float thirstFallRate;
//hunger variables
public UnityEngine.UI.Image hungerBarEmpty;
public float fullHunger;
public float halfHunger;
public float emptyHunger;
public float hungerFallRate;
void Start()
{
}
void Update()
{
if (thirstBarEmpty.rectTransform.anchoredPosition.x>emptyThirst)
{
thirstBarEmpty.rectTransform.anchoredPosition = new Vector2(-=0.1f*(Time.deltaTime / thirstFallRate), 0f);
//thirstBarEmpty.GetComponent<RectTransform>().anchoredPosition.x -= 0.1f * Time.deltaTime / thirstFallRate;
}
if (thirstBarEmpty.GetComponent<RectTransform>().anchoredPosition.x <= emptyThirst)
{
// healthBarEmpty.GetComponent<RectTransform>().anchoredPosition.x -= 0.1 * Time.deltaTime / healthFallRate;
}
}
void CharacterDeath()
{
//DEATH
}
}
Comment
Your answer
Follow this Question
Related Questions
Health Bar NullReferenceException 1 Answer
i have no clue what is wrong with the script (help) 1 Answer
How do i make a colision with a specific object 2 Answers
Asset Store Tools In the drop-down menu no tabs " paskage manager" 0 Answers
Unity Multiplayer: when i hit another player all players health bars go down 0 Answers