Hi, I’m not too well known with C# but I wanted to learn it and picked up on it via Unity with a youtube video. I’m trying to follow a video guide on how to make a 2D game with my own twists to it but I’m kind of stuck now as I want to add an animation to the player’s movement but all I get is 2 error messages that say I can’t add any addition or function to the UnityEngine.Vector2.right and that I can’t convert the type of float to the UnityEngine.Vector2. Does anybody know what my mistake is?
This is my code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerWalk : MonoBehaviour {
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
Movement ();
{
float move = Input.GetAxis("Horizontal");
anim.SetFloat ("Speed", move);
}
}
void Movement()
{
if (Input.GetKey (KeyCode.D)) {
transform.Translate (Vector2.right = 3f * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 0);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate (-Vector2.right = 3f * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 0);
}
}
}