Jump Script, no luck getting it to work..

G’day,

I am trying to make a game and I require the ability to Jump, I have viewed a couple YouTube tutorials without any luck, I have written the code I will post below. The console tells me;

error CS0542: ‘Jump.Jump()’: member names cannot be the same as their enclosing type

Although when overlooking my code, I can not see what this error is talking about, this code is also the same as what was done on youtube.

So I’m looking to find out what is this issue, and any other issue I may occur with making this jump script…

using UnityEngine;
using System.Collections;

public class Jump : MonoBehaviour {

	//Speed
	public float movementSpeed = 5.0f;

	//Controls Player Jump
	private int jumpHeight = 500;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {

		if (Input.GetButtonDown("Jump") || Input.GetKey ("w")) {
			Jump();
		}
	
	}

	void Jump (){
		Rigidbody.AddForce(new Vector3(0, jumpHeight,0), ForceMode.Force);
	}
}

Thanks, I hope I can get a little help! :slight_smile:

P.S, Any great tutorials how to make a sliding background for an infinitive runner…

You can’t have a method Jump inside of a class Jump. Change it to void DoJump or something.

You have the call to the void Jump before the definition of void Jump.
Try moving up the code block

void Jump () {
    Rigidbody.AddForce(new Vector3(0, jumpHeight,0), ForceMode.Force);
}