Hi guys, I’m trying to do a control Point with two teams blue and red. I want my flag to go up & down a post. when the red team is in the circle the flag goes up and when the blue team comes in the circle the flag goes down change color and goes up with the new color on the flag.
Everything is working except when the flag is supposed to go up after changing color. It just magically appear at the top of the post. Can you guys help me?
public class ControlPoint : MonoBehaviour
{
//Ne pas oublier de changer le tag du joueur
public string redTeam = "Player";
public string blueTeam = "Player1";
[SerializeField] public float captureTime = 5f;
[SerializeField] public float capRadius = 5f;
[SerializeField] public ParticleSystem particle;
bool particleRed = true;
bool particleBlue = true;
public float redCapture;
public float blueCapture;
public bool redCaptureStatus;
public bool blueCaptureStatus;
Collider[] colliders;
// flag shader that changes color
//control shader !!!! plusieurs points = plusieurs shader pour que la couleur ne change pas sur tout les points
public Material shader;
//control de la transition + scale
Vector3 startPosition;
[SerializeField] GameObject target;
public GameObject flag;
Vector3 targetPosition;
Vector3 scalePosition;
Vector3 scaleTarget;
float scaleXSize = 1.5f;
float timeToReachTarget;
float temps;
float tempsDescendre;
void Start()
{
redCaptureStatus = false;
blueCaptureStatus = false;
redCapture = 0;
blueCapture = 0;
//shader + flags
//position
startPosition = flag.transform.position; //todo get le flag position verifier si sa fonctionne
targetPosition = target.transform.position;
timeToReachTarget = captureTime;
//scale
scalePosition = flag.transform.localScale;
scaleTarget = new Vector3(scaleXSize, 1, 1);
}
void Update()
{
colliders = Physics.OverlapSphere(transform.position, capRadius);
if (colliders.Length>0 && colliders != null)
{
for (int i = 0; i < colliders.Length; i++)
{
if (TeamCount(blueTeam, colliders) != TeamCount(redTeam, colliders) || TeamCount(redTeam, colliders) != TeamCount(blueTeam, colliders))
{
if (colliders[i].tag == blueTeam)
{
if (blueCapture < captureTime)
{
blueCapture += Time.deltaTime;
if (blueCapture > -captureTime)
{
redCapture -= Time.deltaTime;
if (redCapture > blueCapture)
{
tempsDescendre += Time.deltaTime / timeToReachTarget;
flag.transform.position = Vector3.Lerp(targetPosition, startPosition, tempsDescendre);
flag.transform.localScale = Vector3.Lerp(scaleTarget, scalePosition, tempsDescendre);
}
if(blueCapture > redCapture)
{
temps += Time.deltaTime / timeToReachTarget;
flag.transform.position = Vector3.Lerp(startPosition, targetPosition, temps);
flag.transform.localScale = Vector3.Lerp(scalePosition, scaleTarget, temps);
shader.SetColor("Color_E1736ED4", Color.blue);
}
}
}
else
{
blueCaptureStatus = true;
redCaptureStatus = false;
}
}