Newb friendly error x.x conversion float to int

Assets/_Scripts/_Player/PlayerLevel.cs(33,18): error CS0266: Cannot implicitly convert type double' to int’. An explicit conversion exists (are you missing a cast?)
i couldnt find a problem relative enough to mine in forums for me to fix this myself please help

using UnityEngine;
using System.Collections;

public class PlayerLevel : MonoBehaviour {
	private int curLevel = 1;
	private int maxlevel;
	public int curExp = 99;
	private int maxExp = 100;
	public float expBarLength;
	private int PlayerHealth;
	private bool LevelUp = false;
	void Start () 
	expBarLength = Screen.width / 2;
	void Update () 
	PlayerHealth playerHealth = gameObject.GetComponent<PlayerHealth>();
    AdjustCurrentExp (0);
	if(curExp >= maxExp)
	curExp = 1;
	maxExp += (20 * curLevel);
    playerHealth.endurance += (0.5 * curLevel);
	void OnGUI()
		GUI.Box(new Rect(20, 50, expBarLength, 20), curExp + " / " + maxExp);
		GUI.Box(new Rect(20, 20, 80, 20), "Level: " + curLevel);
	public void AdjustCurrentExp(int adjExp)
		curExp  += adjExp;
		expBarLength = (Screen.width / 3 * curExp / (float)maxExp);

Should be 0.5f, not 0.5. Although then you’d have to cast to int; you’d be better off just doing playerHealth.endurance += curLevel / 2;

This happens because when you write the number

0.5 // or any other number of the form 'digits.digits'

the type of the number defaults to ‘double’. If you instead want it to be treated as a float, you should use


this will make it a float literal instead of a double. Of course, this isn’t neccesarily the problem- I need to know what type ‘PlayerHealth.endurance’ is.

Looking through your code, I can see several serious issues with it. For starters, you seem to have a type “PlayerHealth”- I assume that this is a different MonoBehaviour script on your object. However, you also have a member “PlayerHealth”, which is an integer!! This will cause serious confusion in your code, and you need to make sure that every name and token you use is unique (for exactly this reason).

Wwell i was following tutorials i understand a bit of whats happening in scripts
But then again not at all lol
its tied into playerLevel (thats not part of what i understand lol, if itll help better
Understand what some things in this script are ill post the
Script, but first ill try both of your suggestions! Thanks very kindly!!