Home > Net >  I just want to do a SIMPLE horizontal movement and i have no idea at all what am doing wrong
I just want to do a SIMPLE horizontal movement and i have no idea at all what am doing wrong

Time:08-21

using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;

public class cc2d : MonoBehaviour
{
    public Rigidbody2D rb;
    public float movementspeed = 100f;
    float hmovement;
    float vmovement;

    // Update is called once per frame
    void Update()
    {
        hmovement = Input.GetAxisRaw("Horizontal");
        vmovement = Input.GetAxisRaw("Vertical");      
    }

    void FixedUpdate()
    {
        if (hmovement > 0f || hmovement<-0f)
        {
            rb.AddForce(new Vector2(hmovement * movementspeed,0,0),ForceMode2D.Impulse);
        }
    }

The errors are (in unity debug itself and not in visual studio)

Assets\scripts\cc2d.cs(24,29): error CS0104: 'Vector2' is an ambiguous reference between 'UnityEngine.Vector2' and 'System.Numerics.Vector2'

CodePudding user response:

Delete using System.Numerics; in your script.

You just want to use the UnityEngine.Vector2 Vector.

CodePudding user response:

Your file uses both System.Numerics and UnityEngine, both of which define a type called Vector2, so the compiler gets confused.
The solution? Either get rid of using System.Numerics as you don't seem to be using it anywhere or replace Vector2 with UnityEngine.Vector2 to explicitly tell the compiler that you want the Vector2 from UnityEngine and not System.Numerics
Option 1: Exactly as you have it right now, but without the using System.Numerics; at the top Option 2: (not recommended as Unity types are needed often) replace every instance of Vector2 with UnityEngine.Vector2

  • Related