Need help with this code trying for days now

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?)

line 45 (46 in the code as formatted here in the forum) you have a switch clause for the variable ‘path’.

‘path’ is of type float.

Your cases are of type int.

Furthermore floats are really bad for one to one comparison (float error).

Looking at your code I can’t see any reason why ‘path’ should be a float, change it’s type to int. (You may need to use Mathf.FloorToInt, instead of Mathf.Floor)

Otherwise if you really need ‘path’ to be a float, then in your switch statement you need to convert it to an int.

1 Like

Based on your usage I would make path an int instead of a float.

thanks bro i change it back to a int and change Math.floorToInt and it working fine just so yellow error lets me show you

Most of those warnings are saying you never assign a value to your variables. If you have plans to use those variables later you can ignore those warnings. If not, you might as well delete them and save yourself some memory.

partner i space my time fixing this script and it not working not spawn my enemy space rite like come for a right side of the screen in a circle position i am trying my best to make a script like that but i keep looking on the internet, i did find some but there don’t work so i want to know if you anything or script or some tutorial