So i’ve been stuck lately. Ive been following this tutorial for my playermovement but got stuck.
(
)
Here is the code.(pretty sure the problem is on line 25,i dont get it)
using UnityEngine;
public class Move2d : MonoBehaviour {
public float moveSpeed = 5f;
// Start is called before the first frame update
void Start() {
{
}
// Update is called once per frame
void Update() {
Jump();
{
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
}
void Jump(){
if (Input.GetButtonDown("Jump")){
gameObject.GetComponent<RigidBody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
}
using UnityEngine;
public class Move2d : MonoBehaviour
{
public float moveSpeed = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
}
void Jump()
{
if (Input.GetButtonDown("Jump"))
gameObject.GetComponent<RigidBody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
I tried this and got this error even tho i have a RigidBody2D
Assets\Move2d.cs(20,37): error CS0246: The type or namespace name ‘RigidBody2D’ could not be found (are you missing a using directive or an assembly reference?)
Uh so,i continued the tutorial and now this happened
Assets\Grounded.cs(30,1): error CS1022: Type or namespace definition, or end-of-file expected
Grounded script:
using UnityEngine;
public class Grounded : MonoBehaviour {
GameObject Player;
// Start is called before the first frame update
void Start()
{
Player = gameObject.transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag == "Ground")
Player.GetComponent<Move2D>().isGrounded == true;
}
private void OnCollisionExit2D(Collision2D collision)
if (collision.collider.tag == "Ground")
{
Player.GetComponent<Move2D>().isGrounded == false;;
}
}
Move2d:
using UnityEngine;
public class Move2d : MonoBehaviour
{
public float moveSpeed = 5f;
public bool isGrounded = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
}
void Jump()
{
if (Input.GetButtonDown("Jump") && isGrounded == true)
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
Not related to your topic, but you don’t have to include a poll in your thread.
Just leave the form fields for the poll empty when creating a thread, and it won’t be included.
Then the same thing applies to you: GO FIX YOUR TYPING MISTAKES!
Here is how:
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.