So, I’m trying to make script detect GameObject’s coordinate/vector2 and then use it to move to it’s spot. So those GameObject’s are like nodes to which you can travel. This is how my script looks so far, I think it will explain what I want it to be like, and I know that it’s wrong but I believe you’ll get the point.
using UnityEngine;
using System.Collections;
public class WorldMapMovement : MonoBehaviour
{
public float smooth;
public GameObject Town1;
public GameObject Town2;
private Vector2 travelPosition;
void Awake ()
{
travelPosition = transform.position;
Town1 = GameObject.Find("Town1");
Town2 = GameObject.Find("Town2");
}
void Update ()
{
TravelChanging();
}
void TravelChanging ()
{
Vector2 positionA = Vector2(Town1);
Vector2 positionB = Vector2(Town2);
if(Input.GetKeyDown(KeyCode.Q))
travelPosition = positionA;
if(Input.GetKeyDown(KeyCode.E))
travelPosition = positionB;
transform.position = Vector2.Lerp(transform.position, travelPosition, smooth * Time.deltaTime);
}
Thanks in advance! Zukas.