Question by
ReubenClare123 · Jun 16, 2019 at 12:29 PM ·
animationcharactercontrollerflipping
Trying to flip sprite but cant fix this error =)
Hi guys, Im trying to flip my sprite but I cant get pat this error. I've written my code but at the end it says } expected, but when I put one It causes the rest of my code to have errors. This is the line - transform.localScale = new Vector2(0.551642f, 0.56721f); It's on line 45 I believe. Thanks =)
Here's my code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerPlatformerController : PhysicsObject {
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
private SpriteRenderer spriteRenderer;
public Animator animator;
private object isTouchingGround;
public float movement;
private Animator playerAnimation;
public new Rigidbody2D rigidbody;
public float speed;
public bool isActiveAndEnabledTouchingGround { get; private set; }
// Use this for initialization
void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
}
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
Vector2 horizontal = new Vector4(Input.GetAxis("Horizontal"), -6.11f, -1.52f);
; move.x = Input.GetAxis("Horizontal");
movement = Input.GetAxis("Horizontal");
if (movement > 0.01f)
rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y);
transform.localScale = new Vector2(0.551642f, 0.56721f);
else if (movement < 0.01f)
rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y);
transform.localScale = new Vector2(-0.551642f, 0.56721f);
playerAnimation.SetFloat("Speed", Mathf.Abs(rigidbody.velocity.x));
playerAnimation.SetBool("OnGround", isActiveAndEnabledTouchingGround);
animator.SetFloat("Speed", Input.GetAxis("Horizontal"));
if (Input.GetButtonDown("Jump") && grounded)
{
velocity.y = jumpTakeOffSpeed;
}
else if (Input.GetButtonUp("Jump"))
{
if (velocity.y > 0)
{
velocity.y = velocity.y * 0.5f;
}
}
playerAnimation = GetComponent<Animator>();
rigidbody = GetComponent<Rigidbody2D> ();
targetVelocity = move * maxSpeed;
}
}
Comment