using UnityEngine;
public class Movement : MonoBehaviour
{
public float playerspeed;
private Rigidbody2D rb;
private Vector2 playerdirection;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb = GetComponent<Rigidbody2D>;
}
// Update is called once per frame
void Update()
{
float directionX = Input.GetAxisRaw("Horizontal");
float directionY = Input.GetAxisRaw("Vertical");
playerdirection = new Vector2(directionX, directionY).normalized;
}
void FixedUpdate()
{
rb.velocity = new Vector2(playerdirection.x * playerspeed, playerdirection.y * playerspeed);
}
Because your Start method and all others below are outside the class. See the closing bracket just above Start.
I am very new to coding and don’t know what that means.
Start with basic tutorials and most importantly, do them 100% PERFECTLY.
If tutorials are insufficient for you, then nothing anyone types in this box will help you either.
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Try this approach:
Imphenzia: How Did I Learn To Make Games:
Ok, Thank you!!
Also your line rb = GetComponent<Rigidbody2D>; should be rb = GetComponent<Rigidbody2D>();
Ok, sounds good!