- Home /
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! :)
P.S, Any great tutorials how to make a sliding background for an infinitive runner..
Answer by Kiwasi · Dec 13, 2014 at 07:33 AM
You can't have a method Jump inside of a class Jump. Change it to void DoJump or something.
Answer by Argonn · Dec 18, 2014 at 03:02 PM
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);
}
Your answer
Follow this Question
Related Questions
script not working on second character 1 Answer
Script not working 0 Answers
Door script not working when door is turned 90 degrees 1 Answer