c# – 当前上下文中不存在名称“Math”

前端之家收集整理的这篇文章主要介绍了c# – 当前上下文中不存在名称“Math”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有下面的代码,我试图围绕PerlinNoise(x,z),所以我把它等于Yscale并试图绕过它.问题是我得到了该行的错误“当前上下文中不存在名称`Math’”.有任何想法吗?
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);
}}}}}

解决方法

using System;

文件的顶部.

或者使用System.Math而不是Math.

原文链接:https://www.f2er.com/csharp/100919.html

猜你在找的C#相关文章