Code Problem, need some help !

Hello Everyone !
With some friend, we are planning to create a custom Tower defence. I’m preparing everything and I got a problem in a simple code, there it is, there is 2 scripts, first is the Mobb script and the sedonc is the GameManager, My problem is that I can’t start the code cause, there " publicstaticintvie=5;" it’s telling me this " Assets/GameManager.cs(26,22): error CS0029: Cannot implicitly convert type int' to bool’ "

Here is the full paste code with a line of separation between both scripts:
GameManager :

using UnityEngine;
using System.Collections;

publicclassGameManager:MonoBehaviour{

publicstaticintvie=5;
publicTextMeshtextevie;

voidUpdate()
{
if(vie=5){
textevie.text="-----";
}
elseif(vie=4){
textevie.text="----";
}
elseif(vie=3){
textevie.text="---";
}
elseif(vie=2){
textevie.text="--";
}
elseif(vie=1){
textevie.text="-";
}
elseif(vie=0){
textevie.text="";
}
}
}

Mobb:

using UnityEngine;
using System.Collections;

publicclasszombie:MonoBehaviour{


privateNavMeshAgentagent;

//Usethisfor initialization
voidStart(){

agent=GetComponent<NavMeshAgent>();
NavMeshPathchemin=newNavMeshPath();
agent.destination=GameObject.Find("victim").transform.position;

}

voidOnTriggerEnter(Collidercol)
{
if(col.gameObject.name=="hitbox_chateau")
{
GameManager.vie--;
Destroy(this.gameObject);
}
}


}

( BTW I tried to replace int by bool but it’s giving me way more errors)
Thk for help, i’m stuck here ^^.

Please use code tags:

I’m sure this is just a formatting issue, but most of your code is missing spaces:

publicstaticintvie=5;

should be:

public static int vie=5;

Also, I noticed in your first script’s Update() method, you compare vie to 5 using the ‘=’ operator:

if (vie=5) {

You should be using the equality operator: ‘==’, otherwise you’re just assigning the value instead.

However, I would recommend using ‘switch’ statements instead:

switch (vie) {
    case 5:
        textevie.text = "-----";
        break;

    case 4:
        textevie.text = "----";
        break;

    case 3:
        textevie.text = "---";
        break;

    case 2:
        textevie.text = "--";
        break;

    case 1:
        textevie.text = "-";
        break;

    case 0:
        textevie.text = "";
        break;
}

Although in this specific case, all of this can be replaced with this simple one line:

textevie.text = new String('-', vie);

Thk for help, the space problem is due to copy paste ^^. Thk a lot

Ah, i did what you did and it gives me another error, Assets/GameManager.cs(38,1): error CS8025: Parsing error

Your error is on line 38 apparently, but I don’t know what your code is.

However, your GameManager should simply be this now:

using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {
    public static int vie = 5;
    public TextMesh textevie;

    void Update() {
        // Create a string of dashes, one for each life
        textevie.text = new String('-', vie); 
    }
}

I’ll try this and i’ll replay you back ^^

Ah, new error Assets/GameManager.cs(10,37): error CS0246: The type or namespace name `String’ could not be found. Are you missing a using directive or an assembly reference? on the string, I let you check it

It doesn’t know what ‘String’ is, so you need to add the namespace it belongs to.
Just add the following to 2nd line of the class:

using System;

string has to be lower case.

Ya, use the lower case ‘string’ instead. You wont need the ‘using’ command I suggested.
I was just copy / pasting from online, and they used the System.String class.

Ok thk

Thk you very much for your help, case solved