// Update is called once per frame void FixedUpdate() { if (reloading && Time.time > lastReloadTime + reloadTime[(int)currentWeapon]) { ammo = maxAmmo[(int)currentWeapon]; reloading = false; } if (health <= 0) { battleArea.addAliveTimeStat(gameObject.name, aliveTime); if (battleArea.kdStatText) { if (gameObject.name.StartsWith("MLAgent")) { battleArea.kdStatText.GetComponent <StatsCounter>().addMLSurviveTime(aliveTime); } else if (gameObject.name.StartsWith("MLDisAgent")) { battleArea.kdStatText.GetComponent <StatsCounter>().addMLDisSurviveTime(aliveTime); } else if (gameObject.name.StartsWith("RBSAgent")) { battleArea.kdStatText.GetComponent <StatsCounter>().addRBSSurviveTime(aliveTime); } else if (gameObject.name.StartsWith("Human")) { battleArea.kdStatText.GetComponent <StatsCounter>().addHumanSurviveTime(aliveTime); } } if (agent.brain) { agent.AddReward(-1f); agent.Done(); //gameObject.SetActive(false); } else { if (destroyOnDied) { battleArea.players.Remove(gameObject); Destroy(statusBar); Destroy(gameObject); } } } else { aliveTime += Time.deltaTime; } if (statusBar) { //uiText.GetComponent<Text>().text = "Health: " + health + "\nAmmo: " + ((reloading) ? "RE.." : ammo.ToString()) + "\n" + agent.GetReward().ToString("0.000"); statusBar.GetComponent <StatusBar>().updateBar(health, ammo, maxAmmo[(int)currentWeapon], reloading); // Offset position above object bbox (in world space) float offsetPosX = transform.position.x + 0.75f; // Final position of marker above GO in world space Vector3 offsetPos = new Vector3(offsetPosX, transform.position.y, transform.position.z); // Calculate *screen* position (note, not a canvas/recttransform position) Vector2 canvasPos; Vector2 screenPoint = Camera.main.WorldToScreenPoint(offsetPos); // Convert screen position to Canvas / RectTransform space <- leave camera null if Screen Space Overlay RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, null, out canvasPos); // Set statusBar.transform.localPosition = canvasPos; } }