user1261404
user1261404

Reputation: 325

The name `Math' does not exist in the current context

I have the Code below and I'm trying to round the PerlinNoise(x,z) so I've put it equal to Yscale and tried to round it. the issue is that I get the error "The name `Math' does not exist in the current context" for that Line. Any Ideas?

using UnityEngine;
using System.Collections;

public class voxelcreate : MonoBehaviour {
private int origin = 0;
private Vector3 ChunkSize = new Vector3 (32,6,32);
private float Height = 10.0f;
private float NoiseSize = 10.0f;
private float Yscale=0;
private GameObject root;
public float PerlinNoise(float x, float y)
{
    float noise = Mathf.PerlinNoise( x / NoiseSize, y / NoiseSize );
    return noise * Height;

}

// Use this for initialization
void Start () {
    for(int x = 0; x < 33; x++){
        bool isMultiple = x % ChunkSize.x == 0;
        if(isMultiple == true){
        origin = x;
Chunk();}
    }
}

// Update is called once per frame

void Chunk (){
    int ranNumber = Random.Range(8, 80);
    int ranNumber2 = Random.Range(8, 20);
    Height = ranNumber2;
    NoiseSize = ranNumber;
    for(int x = 0; x < ChunkSize.x; x++)
    {
for(int y = 0; y < ChunkSize.y; y++)
{
    for(int z = 0; z < ChunkSize.z; z++)
    {
GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube);
                int Yscale = (int)Math.Round((PerlinNoise( x, z)), 0);
           box.transform.position = new Vector3( origin+x , y+Yscale, z);
}}}}}

Upvotes: 16

Views: 37418

Answers (3)

Blaze
Blaze

Reputation: 1722

In ASP.NET Core, you need to get the System.Runtime.Extension package first, maybe via NuGet Package Manager in Visual Studio or by command line.

Details about the package can be found here.

Finally you need to give:

using System

And then you can use methods of this class:

            using System;
            namespace Demo.Helpers
            {
                public class MathDemo
                {
                    public int GetAbsoluteValue()
                    {
                        var negativeValue = -123;
                        return Math.Abs(negativeValue);
                    }
                }
            }

Upvotes: 2

user2085599
user2085599

Reputation:

It is true you could add using System. However, Unity has Mathf

Why would you rather use the built in Mathf?

System.Math uses doubles. UnityEngine.Mathf uses floats. Since most of Unity uses floats, it is better to use Mathf so that you don't have to constantly convert floats and doubles back and forth.

Upvotes: 2

Guffa
Guffa

Reputation: 700272

Add

using System;

at the top of the file.

Or use System.Math instead of Math.

Upvotes: 37

Related Questions