Need help with this code that i convert to C# which some in java when i fix one error more just keep poplin up
using UnityEngine;
using System.Collections;
public class Waves : MonoBehaviour {
float aTemp;
float bTemp;
float dTemp;
float cTemp;
float x3Temp;
float x2Temp;
float x1Temp;
GameObject enemy1;
float nextWave;
float path;
public float Posy = 0f;
public float Posx = 3.9f;
int dirTemp;
void Start () {
nextWave = 2.0f;
}
// Update is called once per frame
void Update () {
if (Time.time > nextWave) {
//random number determines the path equation
path = Mathf.Floor (Random.Range(Posy, Posx));
//random number determines direction of motion
if (Random.Range (0.0f, 1.0f) < 0.5f) {
dirTemp = 1;
}
// if(Random.Range(0.0, 1.0) <0.5)
else {
dirTemp = -1;
}
//else (Random.Range(0.0, 1.0) < 0.5)
}
switch (path) {
case 1:
aTemp = Random.Range (0.02f, 0.1f);
x2Temp = Random.Range (-6.0f, 6.0f);
dTemp = Random.Range (-3.0f, 5.0f);
break;
case 2:
aTemp = Random.Range (1.0f, 3.0f);
bTemp = Random.Range (0.2f, 0.4f);
dTemp = Random.Range (0.0f, 5.0f);
break;
case 3:
aTemp = Random.Range (1.0f, 3.0f);
bTemp = Random.Range (0.2f, 0.4f);
dTemp = Random.Range (-5.0f, 5.0f);
break;
default:
print ("Waves.cs: Update(): path out of range");
break;
}
//switch (path)
// Instantiate the enemy with starting position and path to follow
for (float i = 0; i < 5; i++) {
if (path < 3) {
instEnemy (dirTemp * (-12.0f - i * 2.0f), path);
}// if (path < 3)
else {
instEnemy (14f + i * 2.0f, path); // x= f(y)
} // else (path < 3)
}// for 1
nextWave += 5.0f;
// if (Time.time > nextWave)
// Update()
}
void instEnemy (float startPos, float path)
{
Vector3 pos = new Vector3(0.0f,0.0f);
switch (path) {
case 1:
pos.x = startPos;
pos.y = 0.0f;
break;
case 2:
pos.x = startPos;
pos.y = 0.0f;
break;
case 3:
pos.x = 0.0f;
pos.y = startPos;
break;
default:
print ("Wave.cs: instEnemy(): path out of range");
break;
}// switch (path)
pos.z = 0f;
Instantiate (enemy1, pos, Quaternion.identity);
Enemy1 other = GetComponent<Enemy1> ();
other.path = path;
other.a = aTemp;
other.b = bTemp;
other.c = cTemp;
other.d = dTemp;
other.x3 = x3Temp;
other.x2 = x2Temp;
other.x1 = x1Temp;
other.dir = dirTemp;
} // instEnemy
}
Assets/Waves.cs(45,17): error CS0151: A switch expression of type `float’ cannot be converted to an integral type, bool, char, string, enum or nullable type.
Assets/Waves.cs(87,17): error CS0151: A switch expression of type `float’ cannot be converted to an integral type, bool, char, string, enum or nullable type.
Assets/Waves.cs(108,23): error CS0266: Cannot implicitly convert type float' to
int’. An explicit conversion exists (are you missing a cast?)