,my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movment : MonoBehaviour
{
[SerializeField] private Transform start;
[SerializeField] private Transform end;
private void Start()
{
start.position = transform.position;
end.position = transform.position;
}
void Update()
{
Vector2 a = end.position;
if (Input.GetKey("w"))
{
a.y += 2;
end.position = a;
}
if (Input.GetKey("s"))
{
a.y -= 2;
end.position = a;
}
if (Input.GetKey("a"))
{
a.x -= 2;
end.position = a;
}
if (Input.GetKey("d"))
{
a.x += 2;
end.position = a;
}
transform.position = Vector2.Lerp(transform.position, end.position, Time.deltaTime);
}
}
but I have an error in console for some reason;
UnassignedReferenceException: The variable end of Movment has not been assigned.
You probably need to assign the end variable of the Movment script in the inspector.
UnityEngine.Transform.get_position ()
Why???