Hi, I need your help because I can’t really see what’s wrong here.
I want my script to check if “AttEnergy” is more than a particular number (let’s say 101) and if it’s that the case :
- make a simple AttEnergy -= 100 (subtract 100 from the initial value)
- Instantiate and make a copy of himself
My problem is that with my code the object copy himself but “forget” to subtract 100, the strange thing is that if I delete the instantiate line it does subtract 100.
Can you help me understanding what’s wrong and how to make it do both the operation ?
using UnityEngine;
using System.Collections;
public class CellController : MonoBehaviour
{
public int AttEnergy;
private int MaxEnergy = 200;
private float RegEnergy = 1;
private float EnergyAdder;
public GameObject ThingToBeCloned;
void Update()
{
if (AttEnergy < MaxEnergy)
{
EnergyAdder += RegEnergy * Time.deltaTime;
AttEnergy = (int)EnergyAdder;
}
if (AttEnergy >= 100)
{
AttEnergy -= 100;
CloneFunction();
}
}
void CloneFunction()
{
Instantiate(ThingToBeCloned,
transform.position,
transform.rotation);
}
}