I am working through a Unity intro course using C# scripting, and when I try to use the "Mathf" utility I get the error:
The name 'mathf' does not exist in the current context
I am just adding a C# script (Sep23) onto an empty object in the scene. For reference I am following Sebastian Lague's demo: https://youtu.be/zQPyGjPUDVE
My code is below:
using UnityEngine;
using System.Collections;
public class Sep23 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
print ("start");
float dist = GetDistBtwTwoPoints(5, 1, 10, 7);
print(dist);
}
// Update is called once per frame
void Update()
{
}
float GetDistBtwTwoPoints(float x1, float y1, float x2, float y2)
{
float dX = x2-x1;
float dY = y2-y1;
float dstSqrd = dX*dX dY*dY;
float dst = mathf.sqrt(dstSqrd);
return dst;
}
}
CodePudding user response:
Capitalization matters.
float dst = Mathf.Sqrt(dstSqrd);