- Home /
The question is answered, right answer was accepted
warning CS0414: The private field `ChangeToSecondForm.playerToBeChangedFrom' AND `ChangeToSecondForm.playerChangingTo' is assigned but its value is never used
I feel incredibly dumb not knowing what to do. I have tried figuring this out since yesterday and still proves to be out of my grasp of solving this. It seems to me that the private game objects that I had set for myself is clearly (at least to me) been assigned but it continues to say that it is not. Is it the way I set my script up? How can I remember next time not to trip over myself on this problem that seems deceptively easy? Any advice would be very appreciated.
using UnityEngine;
using System.Collections;
public class ChangeToSecondForm : MonoBehaviour
{
private static ChangeToSecondForm instance = null;
public static ChangeToSecondForm Instance
{
get {return instance; }
}
private GameObject playerToBeChangedFrom;
private GameObject playerChangingTo;
public Transform secondFormDisplay;
public int maxEnergy = 100;
public int currentEnergy;
private float energyOriginalXScale;
// Use this for initialization
void Start ()
{
currentEnergy = 0;
energyOriginalXScale = secondFormDisplay.localScale.x;
playerToBeChangedFrom = GameObject.FindGameObjectWithTag ("PlayerCharacter");
playerChangingTo = GameObject.FindGameObjectWithTag ("PlayerCharacterSecondForm");
}
// Update is called once per frame
void Update ()
{
if (currentEnergy <= 0)
{
secondFormDisplay.GetComponentInChildren<Renderer>().enabled = false;
}
if (Input.GetButtonDown ("TransformToSecond") && (currentEnergy == 100))
{
Debug.Log("Q has been pressed");
currentEnergy = 0;
}
}
public void GatherEnergy(int energyGathered)
{
Debug.LogError ("Got Energy from dead enemy.");
currentEnergy += energyGathered;
if (currentEnergy > 100)
{
currentEnergy = 100;
}
secondFormDisplay.localScale = new Vector3(energyOriginalXScale * (currentEnergy/maxEnergy), secondFormDisplay.localScale.z, secondFormDisplay.localScale.z);
}
}
Answer by smoggach · Jan 21, 2015 at 09:50 PM
There's nothing wrong. The compiler is just letting you know that you're not doing anything with those variables other than assigning them a value in Start() If you never access the information after you set it there's really no point in having it. This warning is very useful for pointing out variables you are no longer using.
Answer by Chris333 · Jan 21, 2015 at 09:50 PM
Hi, that is actual a warning and not a error. So your script should just run fine. It just says that u are assigning variables but you are not using them. So you could delete them.
Follow this Question
Related Questions
Translating js to c#, getting NULLReferenceExeption 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers