how do i fix the compiler errors on unity 5? i have tried everything there is to try.
here are the errors
There are inconsistent line endings in the 'Assets/CScripts/movement.cs' script. Some are Mac OS X (UNIX) and some are Windows. This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.
Assets/CScripts/movement.cs(21,2): error CS1520: Class, struct, or interface method must have a return type
Assets/CScripts/movement.cs(23,43): error CS1525: Unexpected symbol
;', expecting
)' or,' 4. Assets/CScripts/movement.cs(26,8): error CS1525: Unexpected symbol
moveVel'
and here is my code
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class movement : MonoBehaviour {
public float Speed = 10, jumpVelocity = 10;
Transform myTrans;
Rigidbody2D myBody;
bool isGround = false;
void Start ()
{
myBody = this.RigidBody2D;
myTrans = this.Transform;
}
fixedUpdate ()
{
move(Input.GetAxisRaw("Horizontal"));
}
Vector2 movevel = myBody.velocity
moveVel.x = horizontalInput* Speed;
public void move(float horizontalInput)
{
myBody.velocity = moveVel;
}
}
Please email me back on how to fix it at: Lime2004@icloud.com
Item number 1 is not an error, they are warnings and you can ignore them. If you want to fix them there is a free asset in the asset store called Line Endings Fixer that works great at taking care of the line ending warnings.
As for your code
You needed a
void
beforefixedUpdate()
.fixedUpdate()
is not a$$anonymous$$onoBehaviour
function and will never be called. Ins$$anonymous$$d it needs to beFixedUpdate()
.The 2 lines above
public void move
are out of place, I moved them into the move function.You need a
;
right afterVector2 movevel = myBody.velocity
.myBody = this.RigidBody2D;
should bemyBody = gameObject.GetComponent<Rigidbody2D>();
.myTrans = this.Transform;
should bemyTrans = transform;
.You have
movevel
defined but you are referencingmoveVel
. I changed the definition tomoveVel
.
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class $$anonymous$$ovement : $$anonymous$$onoBehaviour {
public float Speed = 10;
public float jumpVelocity = 10;
Transform myTrans;
Rigidbody2D myBody;
bool isGround = false;
void Start ()
{
myBody = gameObject.GetComponent<Rigidbody2D>();
myTrans = transform;
}
void FixedUpdate ()
{
move(Input.GetAxisRaw("Horizontal"));
}
public void move(float horizontalInput)
{
Vector2 moveVel = myBody.velocity;
moveVel.x = horizontalInput * Speed;
myBody.velocity = moveVel;
}
}
Your answer
Follow this Question
Related Questions
How to move a cube by flipping using keyboard input 1 Answer
Script Error: OnCollisionEnter2D 1 Answer
Error status 0xc0000020 unity 5.4.0f3 2 Answers
File error on new project 1 Answer