Other
Do Something Once
What I want to happen is that every time the "this", or the card, is placed under the parent of "Placement" for the potatoCostTotal to increase by 4. But everything I've tried only makes it do so once or constantly keeps adding 4. How do I get it to do it only on the first frame that the card is placed under the "Placement" parent.
using UnityEngine;
using UnityEngine.UI;
public class PotatoScore : MonoBehaviour {
public int costAdding = 4;
public int potatoCostTotal = 0;
public bool isTrue;
void Update () {
Debug.Log(potatoCostTotal);
}
void SetCostTotal()
{
if (this.transform.parent.name == "Placement")
{
potatoCostTotal += costAdding;
}
}
}
Answer by tormentoarmagedoom · Apr 23, 2018 at 10:21 AM
Good day.
You can create a bool variabe called for eaxmple "CostAsigned", and do something like this:
void SetCostTotal()
{
if (this.transform.parent.name == "Placement" && CostAsigned == false)
{
potatoCostTotal += costAdding;
CostAsigned=true;
}
}
So once cost is assigned, it will not longer do it.
If helped, accept the answer/close the question!
Bye!
Follow this Question
Related Questions
C# Update Function Question 2 Answers
how's the relationship between updates? 0 Answers
How to call a function in update only once (C#) 1 Answer
Game crashing when im trying to use Inapp update(Unity) 0 Answers
void Update() problem 1 Answer