why do i get the "cant convert float to int" error

i really dont know why this happens and it happens too much times for me
so here is the part of the script that uses floats but if the whole script is needed im gonna paste it.
i pasted the real one now since you got confused

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class lobbyanddead : MonoBehaviour
{
    public GameObject play;
    public GameObject scp457;
    public GameObject scp008;
    public GameObject scp173;
    public float blink = 4.0f;
    public int health = 100;
    public bool infected = false;

    void Update()
    {
        blink -= 1.0f * Time.deltaTime;
        if(blink <= 0.9f)
        {
            blink = 4.0f;
        }
        if (health <= 1);
        {
            health = 100;
            transform.position = new Vector3(10, 1, -400);
            transform.Rotate(0, 0, 0);
        }
        if(infected == true)
        {
            health -= 1 * Time.deltaTime;
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject == play)
        {
            transform.position = new Vector3(22, 1, -69);
            transform.Rotate(0, 0, 0);
        }
        else if (collision.gameObject == scp457)
        {
            transform.position = new Vector3(10, 1, -400);
            transform.Rotate(0, 0, 0);
        }
        else if (collision.gameObject == scp008)
        {
            health -= 10;
            infected = true;
            transform.Translate(Vector3.forward * Time.deltaTime * 10);
        }
        else if (collision.gameObject == scp173)
        {
            if(blink <= 1)
            {
                transform.position = new Vector3(10, 1, -400);
                transform.Rotate(0, 0, 0);
            }
        }
    }
}
}

You got errors in your if statements. single = means assignment, you need to use == (two) to compare objects/values.

And is this your pseudocode, as there’s a lot of other stuff wrong too that will not compile?

Paste the, if not the whole script, at least the exact script. There’s quite a few things in the code (lowercase “o” in “collision.gameObject”, = instead of == in the if clause, etc) as written here that would be errors if written in the actual code, which is making it harder to find the actual problem. And always paste the exact error, including the line number, which will point to the actual problem.

When you need help solving syntax problems, every single character is important, so don’t try and paraphrase your code, as that will almost always obscure the the real problem.

At what line ?

if(collision.gameobject = something)
          {
              Console.WriteLine("example");
          }

This statement won’t produce a compile error since it first assign ‘something’ to ‘compare collision.gameobject’ and then compare the later against null.
But this is probably an undesired behaviour

here is the whole code i was just asking about the float and i typed the code on my phone so here is the one that isnt typed manually:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class lobbyanddead : MonoBehaviour
{
    public GameObject play;
    public GameObject scp457;
    public GameObject scp008;
    public GameObject scp173;
    public float blink = 4.0f;
    public int health = 100;
    public bool infected = false;

    void Update()
    {
        blink -= 1.0f * Time.deltaTime;
        if(blink <= 0.9f)
        {
            blink = 4.0f;
        }
        if (health <= 1);
        {
            health = 100;
            transform.position = new Vector3(10, 1, -400);
            transform.Rotate(0, 0, 0);
        }
        if(infected == true)
        {
            health -= 1 * Time.deltaTime;
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject == play)
        {
            transform.position = new Vector3(22, 1, -69);
            transform.Rotate(0, 0, 0);
        }
        else if (collision.gameObject == scp457)
        {
            transform.position = new Vector3(10, 1, -400);
            transform.Rotate(0, 0, 0);
        }
        else if (collision.gameObject == scp008)
        {
            health -= 10;
            infected = true;
            transform.Translate(Vector3.forward * Time.deltaTime * 10);
        }
        else if (collision.gameObject == scp173)
        {
            if(blink <= 1)
            {
                transform.position = new Vector3(10, 1, -400);
                transform.Rotate(0, 0, 0);
            }
        }
    }
}

Make health a float and it will probably work.

You’re currently subtracting Time.deltaTime from health on line 30. Because health is an int, it doesn’t have anywhere to store those fractions of numbers, so the data would be lost. The compiler is basically just checking to make sure that that loss is what you intended (and it’s clearly not, in this case).

1 Like

Thank you it worked!!!

Why are you multiplying by 1?