Question by
danfogira · Aug 02, 2020 at 11:21 PM ·
c#errorscript error
I need help with my code please
Hello,I need help My code is in error,any assitance would be appreciated :) here are the errors
Assets\Player\script\NewBehaviourScript.cs(5,48): error CS1003: Syntax error, ',' expected
Assets\Player\script\NewBehaviourScript.cs(6,6): error CS1003: Syntax error, ',' expected
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
bool canJump
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update(){
if (Input.GetKey("a"))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1000f * Time.deltaTime,0));
}
if (Input.GetKey("d"))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000f * Time.deltaTime,0));
}
if (Input.GetKeyDown("w") && canJump)
{
canJump = false ;
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0,100f));
}
}
private void OncollisionEnter2D(Collision2D collision)
{
if (collision.transform.tag == "ground")
{
canJump = true;
}
}
}
, Hello,i need help with my code, any assistance would be appreciated My code is throwing 2 errors
Assets\Player\script\NewBehaviourScript.cs(5,48): error CS1003: Syntax error, ',' expected
Assets\Player\script\NewBehaviourScript.cs(6,6): error CS1003: Syntax error, ',' expected
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
bool canJump
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update(){
if (Input.GetKey("a"))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1000f * Time.deltaTime,0));
}
if (Input.GetKey("d"))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000f * Time.deltaTime,0));
}
if (Input.GetKeyDown("w") && canJump)
{
canJump = false ;
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0,100f));
}
}
private void OncollisionEnter2D(Collision2D collision)
{
if (collision.transform.tag == "ground")
{
canJump = true;
}
}
}
Comment
Answer by Llama_w_2Ls · Aug 03, 2020 at 07:59 AM
public class NewBehaviourScript : MonoBehaviour
{
bool canJump;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("a"))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1000f * Time.deltaTime, 0));
}
if (Input.GetKey("d"))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000f * Time.deltaTime, 0));
}
if (Input.GetKeyDown("w") && canJump)
{
canJump = false;
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 100f));
}
}
private void OncollisionEnter2D(Collision2D collision)
{
if (collision.transform.tag == "ground")
{
canJump = true;
}
}
}
Your bool bool canJump
was outside the class and it needed a semicolon after it, thats all