Cannot implicitly convert type 'UnityEngine.GameObjects[]' to 'float'
Hi. I've just started learning to use Unity last month but currently have an assignment of building a game.
Currently I tried to make a 'pop up' pause page when player click the pause button. I followed the tutorial from https://www.sitepoint.com/adding-pause-main-menu-and-game-over-screens-in-unity/ which this tutorial is similar to what I wanted to make.
However, my Unity keeps on popping out the error " Cannot implicitly convert type 'UnityEngine.GameObjects[]' to 'float' ". Im really stuck and don't know how to proceed.
Does anyone have an idea or ways to fix? Please help. Thank you very much.
Answer by jdean300 · May 02, 2017 at 03:13 PM
What are you trying to do with the line Time.timeScale = GameObject.FindObjectsWithTag(...)
?
Time.timeScale is a float
, a decimal number. GameObject.FindObjectsWithTag gives you an array of GameObject, GameObject[]
. You cannot assign an array to a float value.
I was trying to add a pop up window for the pause scene when player clicks the pause button. I try to use the time.timescale code thing for pausing the game. But I guess I used it in the wrong way, but still I'm not sure how should I correct it as I am completely new to c# and Unity. Thanks for your explanation anyway it helps me at least what's the error is about :DD
Answer by AnnaB417 · Aug 28, 2017 at 06:19 PM
@millie2107 It looks like you're combining two steps into one, and by doing that you're mixing a measure of time (float) into a step to call the pause menu (GameObject), which won't work.
Time.timescale should be applied AFTER you've hooked the Game Object to the pause menu. i.e. try something like
GameObject GO_Pause();
void Start() { GO_Pause = GameObject.Find("showOnPause");
// Time.timescale conditions in update hidePaused(); }
void FixedUpdate() //do your pause menu calls here
Your answer
Follow this Question
Related Questions
Reference Vector 3 variable to float variable. 2 Answers
Cannot convert float to int? 1 Answer
Converting object to float in unity? 1 Answer
Angular Velocity to zero 0 Answers