I am making a 2D game where you control a shield and you have to block falling obstacles from reaching base. I know that to move something you use rb.addforce
. However, when I do the same for 2D it doesn’t work. I imagine that instead of using a Vector3 you use a Vector2, but it gives me these 2 errors: Assets\Movement.cs(16,25): error CS1503: Argument 1: cannot convert from 'float' to 'UnityEngine.Vector2'
and this one: Assets\Movement.cs(16,25): error CS1503: Argument 1: cannot convert from 'float' to 'UnityEngine.Vector2'
for each time I write the line. Here is my full code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody2D rb;
public Collider2D collider;
public float moveSpeed = 0.1f;
private void Update()
{
if (Input.GetKey("w"))
{
rb.AddForce(0f, moveSpeed);
Debug.Log("w");
}
if (Input.GetKey("s"))
{
rb.AddForce(0f, moveSpeed);
Debug.Log("s");
}
}
}