- Home /
Does anybody know why im getting new errors when i updated to unity5.
All of a sudden I've been getting "The variable "" is assigned but is never used" on some of my scripts. For example
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RecipeCreator : MonoBehaviour {
public RecipeCreator() {
Recipe WoodPlanks = new Recipe ("WoodPlanks", new Dictionary<string, int> (){
{"Wood", 1}
});
Recipe Knife = new Recipe ("Knife", new Dictionary<string, int> (){
{"Stick", 1}, {"Stone", 1}
});
Recipe Stick = new Recipe ("Stick", new Dictionary<string, int> (){
{"Wood", 1}
});
Recipe TriPod = new Recipe ("TriPod", new Dictionary<string, int> (){
{"Stick", 3}, {"String", 1}
});
Recipe FirePit = new Recipe ("FirePit", new Dictionary<string, int> (){
{"Stick", 5}, {"Stone", 10}, {"Wood", 1}
});
Recipe Axe = new Recipe ("Axe", new Dictionary<string, int> (){
{"Stick", 1}, {"Stone", 3}
});
Recipe Bow = new Recipe ("Bow", new Dictionary<string, int> (){
{"Stick", 2}, {"String", 1}
});
}
}
This is the script im using to create recipes for crafting, it's giving the error for each item. Before i updated unity i never got these errors.
Answer by dethtoll · Mar 19, 2015 at 03:45 AM
The "errors" (more likely warnings) appear to be correct. In the script above, you appear to be creating objects and assigning them to local variables, but never using the variables again within the function.
I'm assuming the constructor for Recipe has side effects (otherwise, what's the point of this code at all?). You don't actually need to assign the results to local variables. Just call "new" without assigning the result to anything.
If you really just want to disable the warnings, you this link may help.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
NetworkManager add spawnable prefabs through code 0 Answers
C# - Doesn't Unity support Expression Bodied Properties? 3 Answers