I tried to make a 2D movement script in unity 2D, i keep getting errors that say nothing that makes sense to me, heres all the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
private float Speed = 0f;//will be changed by other floats, DO NOT CHANGE
public float MaxSpeed = 10f;//This is the max speed that the player can go up to
public float Acceleration = 10f;//How fast the MaxSpeed is reached
public float Deceleration = 10f;//How fast no movement is reached
public Animator anim;
void Update()
{
float direction = Input.GetAxisRaw("Horizontal");
Debug.Log (direction);
//left is -1
//nothing is 0
//right is 1
anim.SetFloat("Speed", Mathf.Abs(Speed));
if (direction = 1) //Right
{
if (Mathf.Abs(Speed) > MaxSpeed)
{
Mathf.Abs(Speed) = MaxSpeed; //If Speed is over MaxSpeed, set it to maxSpeed
} else
{
Speed = Speed + Acceleration * Time.deltaTime; //else acceleration is added
}
} else if (direction = -1) //Left
{
if (Mathf.Abs(Speed) < MaxSpeed)
{
Mathf.Abs(Speed) = MaxSpeed; //If Speed is over MaxSpeed, set it to maxSpeed
} else
{
Speed = Speed - Acceleration * Time.deltaTime; //else acceleration is minused
}
} else
{
if (Speed > 0) //Right
{
Speed = Speed - Deceleration * Time.deltaTime;
} else if (Speed < 0) //Left
{
Speed = Speed + Deceleration * Time.deltaTime;
} else
{
Speed = 0;
}
//transform.position = transform.position + new Vector3(Speed * Time.deltaTime, 0, 0);
}
transform.position = transform.position + new Vector3(Speed * Time.deltaTime, 0, 0);
}
}
heres the errors I’ve been getting as well