I'm making an Action RPG. Weird thing happening when my model's Transform is changing (meaning: while it's moving around). When my player gets within a certain radius of this model, a "panel" of sorts slides in from the left side of the screen showing its stats (it's name and health). While the model is stationary, everything looks fine, but when the model is moving, sometimes the different GUITextures that make up the panel don't line up correctly. Why? Because the Game Object that displays these GUITextures is rotated for some reason! Below is my functon:
void OnTriggerEnter(Collider e)
{
if (e.gameObject.CompareTag("Player") && EnemyYPosition.getEnemyCount() < 4)
{
attacker = e.gameObject.GetComponent<Transform>();
ep = (Transform)Instantiate(ePanel, Vector3.zero, transform.rotation);
ep.Find("Name").guiText.text = gameObject.name;
players.Add(e.gameObject);
}
}
"ep" is the panel Prefab which has a GUITexture component. It also has two children: an object with just a GUIText (that displays the model's name), and another object with a GUITexture (which displays a gradient bar of variable length called the health bar). Since they're all group as one object, they should all move together, but when my model's movement script is activated, sometimes the different child object end up in different positions. Here are the relevant functions in the script attached to the panel object:
IEnumerator Start()
{
gameObject.transform.position = lossPos;
time1 = Time.time;
time2 = 0.0f;
StartCoroutine(Translation(transform, newPos, 1.0f, MoveType.Time));
while (true)
{
g.pixelInset = new Rect(g.pixelInset.x, g.pixelInset.y,
xHP * guiHP, g.pixelInset.height);
//StartCoroutine(EnemyPanelPosition());
yield return null;
}
}
IEnumerator Translation (Transform thisTransform, Vector3 endPos, float value, MoveType moveType)
{
StartCoroutine(Translation(thisTransform, thisTransform.position,
endPos, value, moveType));
yield return null;
}
IEnumerator Translation (Transform thisTransform, Vector3 startPos, Vector3 endPos, float value, MoveType moveType)
{
float rate = (moveType == MoveType.Time)? 1.0f/value : 1.0f/Vector3.Distance(startPos, endPos) * value;
float t = 0.0f;
while (t < 1.0f) {
t += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, t);
yield return null;
}
}
If anyone can help, that would be great.