Im trying to get the position of a 3d object in my code but i’m stuck trying to set it up, what can i do to fix it?
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Threading;
// counts down from a number, and ends the game when time runs out
public class Timer : MonoBehaviour
{
public TextMeshProUGUI timerText;
public float remainingTime;
public GameObject gameObjectToMove;
public GameObject cubePosition;
void Update()
{
Canvas canvas = FindObjectOfType<Canvas>();
float GameObjectPositionX = cubePosition.x;
float GameObjectPositionY;
if (remainingTime > 0)
{
remainingTime -= Time.deltaTime;
if (remainingTime <= 3)
{
timerText.color = Color.red;
}
}
else if (remainingTime < 0)
{
remainingTime = 0;
Time.timeScale = 0;
gameObjectToMove.transform.position = new Vector3(GameObjectPositionX / 2, GameObjectPositionY / 2, 0);
}
int minutes = Mathf.FloorToInt(remainingTime / 60);
int seconds = Mathf.FloorToInt(remainingTime % 60);
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
}