Can You Help me with this code (It's in C#)

Heres My code
Its in C#
Legend: ____ = Can U Help Me?
-----code-----
public int Jump = 3;
void FixedUpdates()
{
if (Input.GetKeyUp("w"))
        {
            if (Jump > 0)
            {
               int Jump = (Jump - 1);
                rb.AddForce(0, 300, 0);
            }
               // if (Jump == 2)
               // {
              //      WaitForSeconds.(5000);
              //
                //
            }
            else
            {
                rb.AddForce(0, 0, 0);

             

            }
        }
}
-----End code-----
Nicholas RevelloAsked:
Who is Participating?
 
David Johnson, CD, MVPOwnerCommented:
int Jump = (Jump -1);
Error      CS0165      Use of unassigned local variable 'Jump'      29083423      
also instead of public int jump =3;  use
static int jump =3;
using System;

namespace _29083423
{

    class Program
    {
        static int Jump;

        static void Main(string[] args)
            {
            Jump = 3;
            int JJ = Jump;
            do {

                JJ--;
                Console.WriteLine(JJ);
            } while (JJ > 0);

            Console.WriteLine(Jump);
            Console.ReadKey();

        }
    }
}

Open in new window

0
 
Miguel OzSoftware EngineerCommented:
What do you need help with?
(eg. code explanation, missing functionality, bug fixing (The last 2 please be specific of what the requirements and/or problem is including stack trace)
0
 
Dr. KlahnPrincipal Software EngineerCommented:
There has to be more to the program than this.  Where are the headers and the includes?  Where is the main?  We need to see the whole thing, otherwise we are shooting in the dark at a problem that may well be somewhere else.  Show us the compile time errors and the run time errors, too.  If it doesn't compile that's one thing; if it compiles and doesn't run that's another.  The more information you give us, the better we can help you troubleshoot the problem.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
I guess you mean what is this
int Jump = (Jump - 1);

Basically some bad code.  It is meant to reduce the value in Jump (eg. 3 goes to 2) but the int creates a local variable called Jump and then promptly attempts to use it.  For C# it means that Jump starts out as zero (default) so it should be -1 after the line runs.
0
 
David Johnson, CD, MVPOwnerCommented:
answered
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.