gpt4 book ai didi

c# - 当前上下文中不存在名称 `Math'

转载 作者:太空狗 更新时间:2023-10-29 18:20:14 43 4
gpt4 key购买 nike

我有下面的代码,我正在尝试对 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

关于c# - 当前上下文中不存在名称 `Math',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19736600/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com