Search Unity

warning CS0414: The private field `Rocket.currentAmount' is assigned but its value is

Discussion in 'Scripting' started by Unititi, Aug 7, 2013.

  1. Unititi

    Unititi

    Joined:
    Mar 6, 2013
    Posts:
    20
    -------------------------------------------------------

    using UnityEngine;
    using System.Collections;

    public class Rocket : MonoBehaviour {

    float currentAmount;
    float DoSums()
    {
    float amount = 5.0f+55.0f;
    return amount;
    }
    void Update ()
    {
    if(Input.GetButtonUp("jump"))
    currentAmount = DoSums();

    }
    }
    --------------------------------------------------------
    Assets/Rocket.cs(6,15): warning CS0414: The private field `Rocket.currentAmount' is assigned but its value is never used




    When I write this scripts . I have CS0414 problem.
    How can I solve that. Anybody help me plz!
     
    Ark Er Obs likes this.
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    You assign a value to currentAmount but you never use it anywhere. Exactly what the warning says. :)
     
    Ark Er Obs likes this.
  3. GGames

    GGames

    Joined:
    Oct 20, 2012
    Posts:
    66
    First of all,
    Warnings can't stop a game from running. They are not errors.

    As for the warning itself, you aren't using the variable anywhere.

    You are giving it a value:
    Code (csharp):
    1. currentAmount = DoSums();
    But, you are not using it for anything. It's just there with its value, wasting memory.

    An example of using it would be:
    Code (csharp):
    1. Vector3 v = transform.position;
    2. v.x += currentAmount; //You use it here
    3. transform.position = v;
     
    Ark Er Obs likes this.
  4. Unititi

    Unititi

    Joined:
    Mar 6, 2013
    Posts:
    20
    Thx KelsoMRK, GGmaes! I solved it! Have a good day!
     
  5. Ark Er Obs

    Ark Er Obs

    Joined:
    Nov 27, 2014
    Posts:
    2
    using UnityEngine;
    using System.Collections;

    public class Enemy2D : MonoBehaviour {

    // References to My GameManager Script
    public GameManager gameManager;

    // Enemies Starting/Ending Position
    float startingPos;
    float endingPos;

    // Unit Enemy Moves Right
    public int unitsToMove = 5;

    // Enemies Movement Speed
    public int moveSpeed = 2;

    // Enemy Moving Right or Left
    bool moveRight = true;

    void awake ()
    {
    startingPos = transform.position.x;
    endingPos = startingPos + unitsToMove;
    }


    (AI Patrol)
    When I write this scripts . I have CS0414 problem in endingPos, and my AI can't move .
    i wrote this just like toturial, but in tutorial the script work and AI move .

    How can I solve that problem . Anybody help me please !
     
    Last edited: Nov 27, 2014
  6. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Shouldn't you be moving the enemy somewhere...
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4. transform.position=Vector3.Lerp(transform.position,endingPos,moveSpeed*Time.deltaTime);
    5. }
    6.  
    something like that?
     
    Ark Er Obs likes this.
  7. Ark Er Obs

    Ark Er Obs

    Joined:
    Nov 27, 2014
    Posts:
    2
    Thank's .

    i will try it .