this is the script im a beginer so can someone please help
using UnityEngine;
using System.Collections;
public class 2DController : MonoBehaviour
{
public float maxSpeed = 10f;
bool facingRight = true;
animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate () {
(
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("speed", Mathf.Abs(move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if(move > 0 &&!facingRight)
Flip ();
else if(move < 0 && facingRight)
Flip ();
}
void Flip ()
(
facingRight = !facingRight;
vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
)
}
- You cannot start a class name with a number, so ‘2DController’ will need to be something else like 'Controller2D.
- Line 17 needs to be removed.
- On line 32 and Line 27, you need to replace the ‘(’ and ‘)’ with ‘{’ and ‘}’.
- On line 34, you need to change ‘vector3’ to ‘Vecor3’. In C# case matters.
- On line 4 ‘animator’ should be ‘Animator’
Combining the changes:
using UnityEngine;
using System.Collections;
public class Controller2D : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
void Start () {
anim = GetComponent<Animator>();
}
void FixedUpdate () {
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("speed", Mathf.Abs(move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if(move > 0 &&!facingRight)
Flip ();
else if(move < 0 && facingRight)
Flip ();
}
void Flip () {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}