This question was
closed Oct 29, 2016 at 10:36 PM by
Hellium for the following reason:
Duplicate Question
Question by
Shade30000 · Oct 29, 2016 at 10:09 PM ·
errorerrormessage
'UnityEngine.Vector2' does not contain a constructor that takes '1' arguments. error CS1729 How to Fix?
I'm just starting to code in C# and general and I keep on having this compile error and I don't know how to fix it. If any one is able to help that would be very appreciated. :)
using UnityEngine; using System.Collections;
public class PlayerControls : MonoBehaviour {
public float moveSpeed;
private Animator anim;
private bool playerMoving;
private Vector2 lastMove;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
playerMoving = false;
if (Input.GetAxisRaw ("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f )
{
transform.Translate (new Vector3 (Input.GetAxisRaw ("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
playerMoving = true;
lastMove = new Vector2 (Input.GetAxisRaw ("Horizontal"));
}
if (Input.GetAxisRaw ("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f )
{
transform.Translate (new Vector3 (0f, Input.GetAxisRaw ("Vertical") * moveSpeed * Time.deltaTime, 0f));
playerMoving = true;
lastMove = new Vector2 (Input.GetAxisRaw ("Vertical"));
}
anim.SetFloat ("MoveX", Input.GetAxisRaw ("Horizontal"));
anim.SetFloat ("MoveY", Input.GetAxisRaw ("Vertical"));
anim.SetBool ("PlayerMoving", playerMoving);
anim.SetFloat ("LastMoveX", lastMove.x);
anim.SetFloat ("LastMoveY", lastMove.y);
}
}
Comment
Answer by doublemax · Oct 29, 2016 at 10:16 PM
The error message is pretty clear. A Vector2 has two components, x and y. But you're only passing one parameter to the constructor:
lastMove = new Vector2 (Input.GetAxisRaw ("Horizontal"));
So the compiler doesn't know what you want. You have to provide the second component. E.g.:
lastMove = new Vector2 (Input.GetAxisRaw ("Horizontal"), 0f );