Question by
assasin10tx · Aug 16, 2017 at 06:11 AM ·
codepage
how do I fix this code? it says I have an extra { symbol near the bottom.
g System.Collections; using System.Collections.Generic; using UnityEngine;
public class NewBehaviourScript : MonoBehaviour { private Rigidbody2D myRigidbody;
private Animator myAnimator;
[SerializeField]
private float movementSpeedl;
private bool attack;
private bool teleport;
private bool facingRight;
[SerializeField]
private Transform[] groundpoints;
[SerializeField]
private float groundradius;
private LayerMask whatIsGround;
private bool isGrounded;
private bool jump;
private float jumpforce;
// Use this for initialization
void Start ()
{
facingRight = true;
myRigidbody = GetComponent<Rigidbody2D> ();
myAnimator = GetComponent<Animator> ();
}
void Update()
{
HandleInput ();
}
// Update is called once per frame
void FixedUpdate()
{
float horizontal = Input.GetAxis ("Horizontal");
isGrounded = IsGrounded();
HandleMovement (horizontal);
Flip (horizontal);
HandleAttacks ();
ResetValues ();
}
private void HandleMovement(float horizontal)
{
if (!this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("ATK"))
{
myRigidbody.velocity = new Vector2 (horizontal * movementSpeedl, myRigidbody.velocity.y);
}
if (isGrounded && jump)
{
isGrounded = false;
myRigidbody.AddForce (new Vector2 (0, jumpforce));
}
if (teleport && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("teleport"))
{
myAnimator.SetBool ("teleport", true);
}
else if (!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("teleport"))
myAnimator.SetFloat ("speed", Mathf.Abs(horizontal));
{
myAnimator.SetBool ("teleport", false);
}
}
private void HandleAttacks()
{
if (Input.GetKeyDown (KeyCode.Space))
{
jump = true;
}
if (attack && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("ATK"))
{
myAnimator.SetTrigger ("attack");
myRigidbody.velocity = Vector2.zero;
}
}
private void HandleInput()
{
if (Input.GetKeyDown (KeyCode.LeftShift))
{
attack = true;
}
if (Input.GetKey (KeyCode.LeftControl))
{
teleport = true;
}
}
private void Flip(float horizontal)
{
if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
private void ResetValues()
{
attack = false;
teleport = false;
}
private bool IsGrounded()
{
if (myRigidbody.velocity.y <= 0)
{
foreach (Transform point in groundpoints)
{
Collider2D[] colliders = Physics2D.OverlapCircleAll (point.position, groundradius, whatIsGround);
for (int i = 0; i < colliders.Length; i++
{
if (colliders[i].gameObject != gameObject)
{
return true;
}
}
}
}
return false;
}
}
Comment
Answer by SteenPetersen · Aug 16, 2017 at 06:53 AM
This line is missing a ")"
for (int i = 0; i < colliders.Length; i++ // line 152