0

when I run this code it get error when i trying to use Sspeed Argument 3: cannot convert from 'method group' to 'float'

I have try do .ToString()

public Rigidbody dot;
public float Speed = 1000f;
float Sspeed()
{
    float Sspeed = Speed * Time.deltaTime;
    return Sspeed;
}
void Start()
{
    Debug.Log(Sspeed);
}


void FixedUpdate()
{
    if (Input.GetKey("a"))
    {
        dot.AddForce(0, 0, Sspeed);
    }
}
pume
  • 21
  • 2

1 Answers1

1

You're missing your brackets.

dot.AddForce(0, 0, Sspeed());

Debug.Log(Sspeed());

In c# you have to add brackets to call a method, even if it has no arguments. This would work without brackets if Sspeed were a (readonly) Property.

As a side note, Sspeed doesn't look like a function name to me, but more like a class name, you should consider renaming it to something more telling, like getSpeed(), although it's not really a speed you're getting there, but more of a distance. (v = s/t <=> v*t = s)

FalcoGer
  • 2,278
  • 1
  • 12
  • 34