Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jan 23, 2015 at 08:14 PM by Ujean917 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ujean917 · Jan 21, 2015 at 09:44 PM · c#debugsyntax

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);
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Translating js to c#, getting NULLReferenceExeption 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Can Unity track the changes I made to my DLL? 0 Answers

Creation of unnecessary and unwanted cubes 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges