How do I root UI canvas GameObject
I feel like I am getting close to finishing this script . I need to carry over the text in the next scene. I gotten and error. I am thinking I need to declare transform. I gotten this Error CS0246: The type or namespace name `transform' could not be found . I just need to fixed this script . I am also accessing the script the score script from this test. I wondering do I also need to change anything in this script. I've change the operators on the test script . It didn't change anything.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Test : MonoBehaviour {
private MyClockScript myClock;
public GameObject Score;
public GameObject Text;
private ScoreManagerScript scoremanager;
void Awake () {
myClock = GetComponent<MyClockScript>();
scoremanager = GetComponent<ScoreManagerScript>();
Score = GameObject.Find("Tip");
}
void Update ()
{
if (myClock.m_leftTime <= 0 && 0 <= ScoreManagerScript.score)
{
SceneManager.LoadScene("new");
}
}
}
Here is my script :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MyClockScript : MonoBehaviour
{
public transform GameObject;
public int Minutes = 0;
public int Seconds = 0;
private Text m_text;
public float m_leftTime;
public void Awake()
{
m_text = GetComponent<Text>();
m_leftTime = GetInitialTime();
DontDestroyOnLoad (RootCanvas.transform.root);
}
public void Update()
{
if (m_leftTime > 0f)
{
// Update countdown clock
m_leftTime -= Time.deltaTime;
Minutes = GetLeftMinutes();
Seconds = GetLeftSeconds();
// Show current clock
if (m_leftTime > 0f)
{
m_text.text = "Time : " + Minutes + ":" + Seconds.ToString("00");
}
else
{
// The countdown clock has finished
m_text.text = "Time : 0:00";
}
}
}
private float GetInitialTime()
{
return Minutes * 60f + Seconds;
}
private int GetLeftMinutes()
{
return Mathf.FloorToInt(m_leftTime / 60f);
}
private int GetLeftSeconds()
{
return Mathf.FloorToInt(m_leftTime % 60f);
}
}
Answer by hexagonius · Jun 22, 2016 at 06:09 PM
In line 7, you declare
public transform GameObject;
but it's either
public GameObject transform;
or
public Transform GameObject;
the important thing here is, that there is no class called "transform", but "Transform" there is. you should give a proper name however, bacause naming a Transform Gameobject or vice versa is rather confusing.
Your answer
Follow this Question
Related Questions
canvas child of another canvas issue 0 Answers
How can I organize menus as a tree hierarchy? 0 Answers
OnMouseDown work through UI elements 3 Answers
Does using multiple World Space Canvases affect performance? 0 Answers
is there simple way to put random sprite to gameobject multi child with no repating. 1 Answer