I’m writing some Movement code for a 2D shooter however I’m having problems implementing jumping into my game. I have two errors “CS0135” and “CS1660”. I have spent a good hour trying the understand who this problem was coursed and how to prevent it, however most documentation doesn’t make that much sense as I have no real context with what’s wrong.
I’ve put my code bellow along with the who error messages. Please could someone tell me what’s up and help me understand these errors more. Thanks!
Code:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
//Movement Varables
public float speed = 1.0f;
public float maxSpeed = 20.0f;
public float currentSpeed = 0.0f;
private bool moving = false;
//Jumping varables
private bool jumping = false;
public float currentHieght = 0.0f;
public float maxHieght = 20.0f;
// Update is called once per frame
void Update () {
//Section used to update player persition
float x = Input.GetAxis("Horizontal") * Time.deltaTime * currentSpeed;
float y = Input.GetAxis("Vertical") * Time.deltaTime * currentHieght;
transform.Translate(x, 0, y);
//When A or D is pressed which make the player move left or right
if(Input.GetButtonDown("Horizontal"))
moving = true;
//When Shift is held Down making player Run
if(Input.GetButtonDown("Run")){
maxSpeed = 35.0f;
maxHieght = 35.0f;
}
//When Space is Pressed to make player jump
if(Input.GetButtonDown("Jump"))
jumping = true;
//Is Player is moving
if(moving == true)
MovePlayer();
//When your not pressing A or D and your player is still moving
if(Input.GetButtonUp("Horizontal") && currentSpeed > 0)
moving = false;
// Makes player fall
if(moving == false && currentHieght > 0)
Falling();
//Makes Player stop moving
if(moving == false && currentSpeed > 0)
Stop();
//When you release shift Player's running and jumping varables reset to defult
if(Input.GetButtonUp("Run")){
maxSpeed = 20.0f;
maxHieght = 20.0f;
}
}
//Infomation to do with Moving the player
void MovePlayer(){
//If player not running at full speed then player will run faster
if(maxSpeed > currentSpeed)
currentSpeed = currentSpeed + speed;
//if player is running faster than should
if(currentSpeed > maxSpeed)
currentSpeed = currentSpeed - speed;
Debug.Log(currentSpeed);
return;
}
//Infomation to do with stopping the player from moving
void Stop(){
//Slows down player
currentSpeed = currentSpeed - speed;
Debug.Log(currentSpeed);
return;
}
//Infomation to do with making the player Jump
void Jumping(){
//Makes Player jump higher
if(maxHieght > currentHieght)
currentHieght = currentHieght + speed;
//When the player reaches the maximum hight
if(currentHieght => maxHight)
jumping = false;
return;
}
//Infoamtion to do with making the player fall after finishing a jump
void Falling(){
//Makes Player fall
currentHieght = currentHieght - currentSpeed;
return;
}
}
Errors:
(93,24): error CS0135: `currentHieght’ conflicts with a declaration in a child block
(94,25): error CS0135: `currentHieght’ conflicts with a declaration in a child block
(94,9): error CS0135: `currentHieght’ conflicts with a declaration in a child block
(97,12): error CS1660: Cannot convert lambda expression' to non-delegate type bool’
Thank you! My god is that a simple fix.
– Liamh101