This script allows for 2D point-and-click movement along the X-axis only.
To use it:
- Set your game's Movement method to Point And Click, and your Camera perspective to 2D.
- Create a NavMesh that covers the area you wish the Player to move. It does not need to be too thin - it just needs to encompass the area that the Player can move.
- Paste the code below into a C# script named PointClickHorizontal2D, and attach it to any object in your scene
PointClickHorizontal2D.cs
using UnityEngine;
using AC;
public class PointClickHorizontal2D : MonoBehaviour
{
private void OnEnable () { EventManager.OnCharacterSetPath += OnCharacterSetPath; }
private void OnDisable () { EventManager.OnCharacterSetPath -= OnCharacterSetPath; }
private void OnCharacterSetPath (AC.Char character, Paths path)
{
if (character == KickStarter.player)
{
if (path.nodes.Count > 1)
{
path.nodes.RemoveRange (0, path.nodes.Count - 2);
}
Vector3 lastNode = path.nodes[path.nodes.Count-1];
lastNode.y = character.transform.position.y;
path.nodes[path.nodes.Count-1] = lastNode;
}
}
}