- Home /
Not all code paths return a value?
I'm getting an error in Unity that I've never gotten before. It says:
Assets/Scripts/Managers/PlayerFunds.cs(20,22): error CS0161: `PlayerFunds.SaveCredits()': not all code paths return a value
The script I'm writing is very simple so I don't understant what the problem may be. Here is the code:
using UnityEngine;
using System.Collections;
public class PlayerFunds : MonoBehaviour {
public int playerCredits;
void Start() {
playerCredits = PlayerPrefs.GetInt("Credits");
}
public void AddCredits(int amount) {
playerCredits += amount;
}
public void SubtractCredits(int amount) {
playerCredits -= amount;
}
public float SaveCredits() {
PlayerPrefs.SetInt("Credits", playerCredits);
}
}
Answer by whydoidoit · Feb 15, 2014 at 07:43 AM
You have SaveCredits defined to return a float but it doesn't return anything. Looks like it should be "void" to me.
Answer by Mikejr76 · Feb 15, 2014 at 07:54 AM
You have set the return type of SaveCredits() as a float. You have to return a float currently you are not returning anything that is why you are getting the error.
Hope it helps!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Turrets; Error CS0161 C# 1 Answer
Really need help for my code! 2 Answers
Texture2D as a png file. 0 Answers