Text Objects do Lerp
I have a camera, that has a lerp to follow my player smoothly. Now I added text objects and assigned to them the same position as the camera has + x and + y. One object does that and stands on a fixed position on the camera field, but the other 3 do that weird thing where they stay on a point for a few moments and then lerp to the next point. Here is the code for the text object that works and stays on its place:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
[SerializeField]
GameObject mainCamera;
[SerializeField]
GameObject playerSpider;
[SerializeField]
GameObject deadWave;
public DeathsRatio deathsRatio;
public float addToCameraY = 2;
public float addToCameraX = 2;
public Text scoreText;
[SerializeField]
public float score = 0;
// Start is called before the first frame update
void Start()
{
scoreText.text = 0.ToString();
deathsRatio.totalScores = 0;
}
// Update is called once per frame
void Update()
{
transform.position = new Vector2(mainCamera.transform.position.x + addToCameraX, mainCamera.transform.position.y + addToCameraY);
score = playerSpider.transform.position.x + 26;
scoreText.text = "Score: " + score.ToString("F0");
if (playerSpider.transform.position.y < -25)
{
deathsRatio.totalScores += score;
score = 0;
}
if (deadWave.transform.position.x + 4 > playerSpider.transform.position.x)
{
deathsRatio.totalScores += score;
score = 0;
}
}
}
And here is the code for one of the weird moving objects:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Highscore : MonoBehaviour
{
public Score attachedScore;
public float highscore;
public Text highscoreText;
public PlayerController deadChecker;
[SerializeField]
GameObject mainCamera;
public float addToCameraX = 2;
public float addToCameraY = 2;
public GameObject playerSpider;
public GameObject deadWave;
public string newWord;
public bool newWordThere;
// Start is called before the first frame update
void Start()
{
highscore = 0;
highscoreText.text = 0.ToString();
newWord = "";
newWordThere = false;
}
// Update is called once per frame
void Update()
{
transform.position = new Vector2(mainCamera.transform.position.x + addToCameraX, mainCamera.transform.position.y + addToCameraY);
highscoreText.text = newWord + "Highscore: " + highscore.ToString("F0");
//highscore
if (attachedScore.score > highscore)
{
highscore = attachedScore.score;
newWordThere = true;
}
if (attachedScore.score < 0.9)
{
newWordThere = false;
}
if (newWordThere == true && highscore > 0.9)
{
newWord = "New ";
}
if (newWordThere == false)
{
newWord = "";
}
}
}
I've included everything of the code if the error is elsewhere. I have read through it multiple times and I just cannot find the difference between the one functioning and the one that doesn't... Can someone please help me?
Your answer
Follow this Question
Related Questions
Best way to attatch text to text script c# 1 Answer
Access parts of different scripts? 1 Answer
Is it possible for camera to detect a collision between 2 different objects it's looking at? 0 Answers
Move camera between canvases in UI menu 0 Answers
"cannot implicitly convert type `UnityEngine.GameObject' to `UnityEngine.UI.Text' 2 Answers