Error in Unity 3D Javascript code

Asked

Viewed 32 times

0

I’m doing a Voxel World Minecraft style in Unity 3D, but is giving the following problem: BCE0051: Operator '*' cannot be used with a left hand side of type 'System.Type' and a right hand side of type 'float'.

#pragma strict

var TamX: int;
var TamZ: int;

var Terreno: GameObject[,];
var Bloco: GameObject;

var x: int;
var z: int;

var AlturaMaxima = int;
function Start () {
	Terreno = new GameObject[TamX, TamZ];
	for(x=0;x<TamX;x++)
		for(z=0;z<TamZ;z++)
		Terreno[x,z] = Instantiate(Bloco,
		Vector3(x*Bloco.transform.localScale.x,0,z*Bloco.transform.localScale.z),
		Quaternion.identity);
Elevacao(0);
}

function Update () {
	
}

function Elevacao (seed: float)
{
	var altura: int;
	for(x=0;x<TamX;x++)
	for(z=0;z<TamZ;z++)
		{
		altura = AlturaMaxima*Mathf.PerlinNoise((x+seed)/Mathf.Sqrt(TamX),(z+seed)/Mathf.Sqrt(TamZ));
		Terreno[x,z].transform.position.y = Mathf.Floor(altura)*Bloco.transform.localScale.y;
		}
}

I know the problem is on this line

altura = AlturaMaxima*Mathf.PerlinNoise((x+seed)/Mathf.Sqrt(TamX),(z+seed)/Mathf.Sqrt(TamZ));
In it I am trying to apply blocks of height in my land, I would like to make this idea yet, but I do not know how else to accomplish, I appreciate any help.

1 answer

0


what’s going on in your case is that AlturaMaxima is a type, ie you are trying to do a multiplication operation of a type of variable with a floating point variable value, something similar to the following operation:

int * 1.0; //Os valores não correspondem aos reais, porém seus tipos sim.

I suggest you change your code:

var AlturaMaxima = int;

To

var AlturaMaxima: int;
//Ou
var AlturaMaxima = 0;

With this change, the variable Alturamaxima will no longer be a type and will become an integer, which will solve your multiplication error with illegal values.

  • Thank you very much!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.