public float being defined as object?

I have a time script which generates the time Example

using UnityEngine;
namespace TheTime
{
	public class CurrentTime : MonoBehaviour
	{
	
	public float
		TimeH = 0,
		TimeM = 0,
		TimeS = 0;
	
	public bool ActiveTime,Rewind,FastForward;
	
	void Update (){
		
		if (ActiveTime)
		{
			float secondsPassed = Time.deltaTime;

			if (Rewind)
			{
				secondsPassed *= -1250;
				TimeS += secondsPassed;

				if (TimeS <= 0) {
					TimeM--;
					TimeS += 60;
				}
				if (TimeM <= 0) {
					TimeH--;
					TimeM += 60;
				}
				if (TimeH <= 0) {
					TimeH += 24;
				}
			}

That’s just a slice of it, the fast forward and rewind are the same.

Anyway I have another script which handles a clock I made

using UnityEngine;
using TheTime;

	class FFClock : MonoBehaviour {

	public Transform hours, minutes, seconds;

	void Update (){
			{
			hours.localRotation =
				Quaternion.Euler(CurrentTime.TimeH,90,90);
			minutes.localRotation =
				Quaternion.Euler(CurrentTime.TimeM,90,90);
			seconds.localRotation =
				Quaternion.Euler(CurrentTime.TimeS,90,90);
		}
	}
}

the 3 lines all give me

1."error CS1503: Argument #1' cannot convert object’ expression to type float'" 2.error CS0120: An object reference is required to access non-static member TheTime.CurrentTime.TimeM’

The error is not saying float is being defined as an object, it is saying:

CurrentTime.TimeH

is an object expression when it is expecting a float. Which is true.

You are trying to reference current time’s TimeH, TimeM and TimeS attributes from a static context, but they are not declared as static.

To elaborate, by saying:

 public float
TimeH = 0,
TimeM = 0,
TimeS = 0;

You are declaring instance variables. That is - variables accessible from instances of the CurrentTime class. When you are trying to call

CurrentTime.TimeH

You are trying to call a class variable in CurrentTime, of which none exist.

To do what you are doing - you’ll need to declare your CurrentTime class as a singleton, so that you can have a static reference to the only instance of the CurrentTime object. I’m of the camp that singletons and mutable global state is almost always bad, though, so I offer that link in protest :stuck_out_tongue:

You could also have an instance of CurrentTime in your scene, and provide a reference to it in the scripts you need, such as in FFClock.

So in FFClock, you would have something like:

public CurrentTime currentTime;

and then you could referencing the various Time* members via:

currentTime.TimeH

As the error is saying, you either need to make the TimeM member static, or use one which comes from an instance of the class.
If your script is already attached to a GameObject in your scene, you can simply add it as a public variable

public CurrentTime Script;

and then call

hours.localRotation =
          Quaternion.Euler(Script.TimeH,90,90);