Hi I am having some issues with the unity editor.
Im trying to make a 2d platformer and when I added jumping I got the error “CS0131”
Could someone tell me where the issue is?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public float moveSpeed = 10f;
[SerializeField] private bool isGrounded = false;
// Start is called before the first frame update
void Start()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Ground"))
isGrounded = true;
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Ground"))
isGrounded = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
transform.Translate(new Vector3(-2, 0, 0) * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.RightArrow))
transform.Translate(new Vector3(2, 0, 0) * moveSpeed * Time.deltaTime);
if (Input.GetKeyDown("space") && isGrounded = true)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
}