Hey there hope you all are well
so I am making a game where you move around your play in one scene, queue up some waypoints (vector3 positions, Quaternion rotation) that the player then automaticly moves between in a different scene, and I am corrently having some problems populating the database of waypoints.
below is the code used to create a waypoint:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Waypoint : MonoBehaviour
{
public int waypointId;
public Vector3 waypointPosition;
public Quaternion waypointRotation;
public Waypoint(int waypointId, Vector3 waypointPosition, Quaternion waypointRotation)
{
this.waypointId = waypointId;
this.waypointPosition = waypointPosition;
this.waypointRotation = waypointRotation;
}
public Waypoint(Waypoint waypoint)
{
this.waypointId = waypoint.waypointId;
this.waypointPosition = waypoint.waypointPosition;
this.waypointRotation = waypoint.waypointRotation;
}
}
and below is the code for the waypoint database:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaypointDatabase : MonoBehaviour
{
public List<Waypoint> waypoints = new List<Waypoint>();
// Before any Start methods are called run the Awake method thus make sure that the WaypointDatabase is created as one of the first things in the scene.
private void Awake()
{
// Build and populate the database.
BuildWaypointDatabase();
}
// The following method is a method to get a waypoint by it's id.
public Waypoint GetWaypoint(int id)
{
return waypoints.Find(waypoint => waypoint.waypointId == id);
}
// Build database method. Create custom waypoints here for test purposes.
void BuildWaypointDatabase()
{
waypoints = new List<Waypoint>()
{
// new waypoint = int waypointId, Vector3 waypointPosition, Quaternion waypointRotation.
new Waypoint(0,
new Vector3(1, 2, 3),
new Quaternion(0, 0, 0, 1)
),
new Waypoint(1,
new Vector3(2, 2, 3),
new Quaternion(45, 0, 0, 1)
),
new Waypoint(2,
new Vector3(3, 2, 3),
new Quaternion(0, 0, 0, 1)
),
};
}
}
now my goal here is to eventually be able to save/load my list of waypoints from a file, so the progress can be saved from play to play.
in the picture below you can see the result of clicking play ie; what the code currently does on play.
now again what I want the code to do is to load in a series of predefined vector positions and quarternion rotations, so when the scene starts the player/gameobject moves between the points (in order from first to last in list)