Having Error that i can't fix

i have this error for these this
script

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;

    int path;
    int dirTemp;
    void Start () {
        nextWave = 2.0;
   
    }
   
    // Update is called once per frame
    void Update () {
        if (Time.time > nextWave) {
            //random number determines the path equation
            path = Mathf.Floor ( Random.Range(1.0,3.9));

            //random number determines direction of motion
            if (Random.Range (0.0, 1.0) < 0.5) {
                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.02, 0.1);
            x2Temp = Random.Range (-6.0, 6.0);
            dTemp = Random.Range (-3.0, 5.0);
            break;

        case 2:
            aTemp = Random.Range (1.0, 3.0);
            bTemp = Random.Range (0.2, 0.4);
            dTemp = Random.Range (0.0, 5.0);
            break;
       
        case 3:
            aTemp = Random.Range (1.0, 3.0);
            bTemp = Random.Range (0.2, 0.4);
            dTemp = Random.Range (-5.0, 5.0);
            break;
        default:
            print ("Waves.cs: Update(): path out of range");
            break;
        }
        //switch (path)

        // Instantiate the enemy with starting position and path to follow
        for (int i = 0; i < 5; i++) {
            if (path < 3) {
                instEnemy (dirTemp * (-12.0 - i * 2.0), path);
            }// if (path < 3)
            else {
                instEnemy (14 + i * 2.0, path); // x= f(y)
            } // else (path < 3)

        }// for 1
        nextWave += 5.0;
        // if (Time.time > nextWave)
        // Update()
    }

    void instEnemy (float startPos, int path)
    {
        Vector3 pos;
        switch (path) {
        case 1:
            pos.x = startPos;
            pos.y = 0.0;
            break;
        case 2:
            pos.x = startPos;
            pos.y = 0.0;
            break;

        case 3:
            pos.x = 0.0;
            pos.y = startPos;
            break;
        default:
            print ("Wave.cs: instEnemy(): path out of range");
            break;
        }// switch (path)
        pos.z = 0;
        GameObject = 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
}

Just saw your reply to the other thread! This one is due to the variable type, you need to tell the compiler it is a float, for instance…

nextWave =2.0;

becomes

nextWave =2.0f;

1 Like

so can you fix the other error

so for the number so i need to change all of them to float

Yes all the numbers that have a dot (Like 2.0), need to be marked as 2.0f. That should fix all your problems.

New Error my friend copy the script in your project you going see all the error

// Update is called once per frame
    void Update () {
        if (Time.time > nextWave) {
            //random number determines the path equation
            path = Mathf.Floor (Random.Range(1.0f, 3.9f));

            //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)
        }
    void instEnemy (float startPos, int path)
    {
        Vector3 pos;
        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 = 0;
        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
}

I’m not at a computer right now, but firstly I think you need to initialize your Vector3 “pos”.

Vector3 pos = new Vector3(0.0f, 0.0f, 0.0f); // or whatever values you want

Also, first chunk of code on line 5… you’re trying to directly store a random float into an int. It’s C#, so you need to do a proper cast.

partner i got the code from youtube a space shooter from since 2012 and it was java and so i convert it to C# that why i getting all these error i don’t what you by proper casting tomorrow is school

The best way to cast a float to an int you can just put (int) in front of the value, for example myInt = (int)myFloat; . I am at work so don’t have Unity on this PC so I can’t see which line your error is cropping up on.

For more information on casting look at Casting and type conversions - C# | Microsoft Learn

Okay so a have to do is create a function in front of path = mathf.Floor (Random.Range(1.0f,3.9f);
myInt = (int)myFloat;