Hi guys, in my game, im trying to teleport 2 balls with my script that have attached Trail renderers, and when i move them somewhere they leave a trail after them, i have tried to use various solutions, but non of them worked even they should have.
here is my Update method:
void Update()
{
if (Mathf.Abs(timer.GetComponent<NumberUpdater>().elapsedTime % 65) < 0.0101f)
{
if (!jsonCounterUpdated)
{sp.isMatchActive = false;}
jsonCounterUpdated = true; // Prevent multiple updates
}
else
{
jsonCounterUpdated = false; // Reset the flag when the condition is not met
}
if(!sp.isMatchActive)
{
sp.isMatchActive = true;
sp.jsonDataCounter ++;
// Update the teams in Scene Properties
UpdateActiveVar();
// TODO - Reset UI (Hook, comment1, comment2, (CTAs (Follow, Repost)))
// Reset score logic
ResetScore();
// Reset timer logic
ResetTimer();
// Set/Reset Ballz/Spawn logic
// TODO - set the velocity = 0
SetBallz();
// Set/Reset Logos logic
SetLogos();
// Reset Ring
ResetRing();
// Reset/Destory Audio
ResetAndDestroyAudio();
// Disable animations
// Goal
DisableGoalAnim();
// Fans
DisableFansAnim();
// Logos
DisableLogosAnim();
// Reset UI
// WAITING: Hook from Krystof
// comment 1
// comment 2
// CTAs
// Follow
// Repost
}
}
I the method where i reset the ball the SetBallz():
void SetBallz()
{
// Set color and logo to the right Team
rightBall = GameObject.FindGameObjectWithTag("Ball");
rightBall.GetComponent<SpriteRenderer>().color = sp.rightActiveTeam.teamColor;
GameObject rightTeamSprite = rightBall.transform.GetChild(rightBall.transform.childCount - 1).gameObject;
rightTeamSprite.GetComponent<SpriteRenderer>().sprite = sp.rightActiveTeam.teamLogo;
// Set color and logo to the left Team
leftBall = GameObject.FindGameObjectWithTag("Ball1");
leftBall.GetComponent<SpriteRenderer>().color = sp.leftActiveTeam.teamColor;
GameObject leftTeamSprite = leftBall.transform.GetChild(leftBall.transform.childCount - 1).gameObject;
leftTeamSprite.GetComponent<SpriteRenderer>().sprite = sp.leftActiveTeam.teamLogo;
// Set the cordinates of the ballz
GenerateRandomPositions(xMin,xMax,yMin,yMax);
rightBall.GetComponent<TrailRenderer>().emitting = false;
leftBall.GetComponent<TrailRenderer>().emitting = false;
rightBall.transform.position = new Vector3(randomX, randomY, transform.position.z);
leftBall.transform.position = new Vector3(-randomX, randomY, transform.position.z);
rightBall.GetComponent<TrailRenderer>().emitting = true;
leftBall.GetComponent<TrailRenderer>().emitting = true;
}
Or i have tried to use
leftBall.setActive(false);
rightBall.setActive(false);
rightBall.transform.position = new Vector3(randomX, randomY, transform.position.z);
leftBall.transform.position = new Vector3(-randomX, randomY, transform.position.z);
leftBall.setActive(true);
rightBall.setActive(true);
But it did not work as well, and i have no idea what am I doing wrong please help me