Thursday, February 11, 2016

generatorAI

        private int STATE_GENERATING = 1;
private int STATE_DESTROYED = 0;
private float GEN_INTERVAL = 3;
private float CORE_OFFSET = 0.3f;
private float CORE_SPEED = 2f;

public GameObject generatorCore;
public float coreStartPoint;
public float coreEndPoint;
public float coreSpeed;

private int curState;
private float curIntervalTime;

// Use this for initialization
void Start () {

Vector3 pos = generatorCore.GetComponent<Transform>().position;
coreStartPoint = pos.y;
curState = STATE_GENERATING;
curIntervalTime = 0;
coreEndPoint = coreStartPoint + CORE_OFFSET;
coreSpeed = CORE_SPEED;
}

// Update is called once per frame
void Update ()
{
float deltaTime = Time.deltaTime;

if(curState == STATE_GENERATING)
{
animateCore(deltaTime);
}
else
{
//TODO: maybe add some smoke

}



}

private void animateCore(float deltaTime)
{
Vector3 pos = generatorCore.GetComponent<Transform>().position;
pos.y += (coreSpeed * deltaTime);

if((coreSpeed > 0) && (pos.y > coreEndPoint))
{
pos.y = coreEndPoint;
coreSpeed = -CORE_SPEED;
coreEndPoint = coreStartPoint - CORE_OFFSET;
}
else if (coreSpeed<0 && pos.y < coreEndPoint)
{

pos.y = coreEndPoint;
coreSpeed = CORE_SPEED;
coreEndPoint = coreStartPoint + CORE_OFFSET;
}
generatorCore.GetComponent<Transform>().position = pos;
}

No comments:

Post a Comment