Answer the question
In order to leave comments, you need to log in
How to fix movement script error in unity?
I'm learning how to create 2D platformers. I found this script on the Internet, I'm trying to bind it to a character - 8 errors at once. Can anyone fix them?:
using UnityEngine;
using System.Collections;
public class characterController : MonoBehaviour {
public float maxSpeed = 10f;
public float jumpForce = 700f;
bool facingRight = true;
bool grounded = false;
public Transform groundCheck;
public float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float move;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
move = Input.GetAxis ("Horizontal");
}
void Update(){
if (grounded && (Input.GetKeyDown (KeyCode.W)||Input.GetKeyDown (KeyCode.UpArrow))) {
rigidbody2D.AddForce (new Vector2(0f,jumpForce));
}
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
if (Input.GetKey(KeyCode.R))
{
Application.LoadLevel(Application.loadedLevel);
}
}
void Flip(){
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Answer the question
In order to leave comments, you need to log in
maybe. but you need to do it. to learn.
and for the design of the question - arrange the code as a code.) it was not in vain that the markup was done here.
and yet no one is particularly eager to open the project and paste your code there, so at least you would attach error messages from the console (and not with a screenshot, but by copying each with text. and keeping the order, since the first error can simply be trite "pull "follow the rest)
and if you yourself read the description of the error - and google a little and learn some basics of programming - the question will disappear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question