using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI; //important
public class NPCTeleporter : MonoBehaviour
{
private Transform player;
public NavMeshAgent agent;
public CharacterController controller;
public enum TeleportLocation
{
Homebase,
FiringRange,
Arena
}
public TeleportLocation location;
Vector3 GetPosition(TeleportLocation location)
{
switch (location)
{
case TeleportLocation.Homebase:
return new Vector3(-174, 2, -55);
case TeleportLocation.Arena:
return new Vector3(-63, 2, -54);
case TeleportLocation.FiringRange:
return new Vector3(-62, 2, -39);
default:
return new Vector3(-174, 2, -55);
}
}
void Start()
{
agent = GetComponent<NavMeshAgent>();
player = GameObject.Find("Player").GetComponent<Transform>();
controller = GetComponent<CharacterController>();
}
public void TeleportThePlayer(Enum location)
{
if (Vector3.Distance(this.transform.position, player.position) <= agent.stoppingDistance)
{
// Disable the CharacterController.
controller.enabled = false;
// Move it.
controller.transform.position = (GetPosition((TeleportLocation)location));
// Re-enable it.
controller.enabled = true;
//controller.Move(GetPosition((TeleportLocation)location));
//player.transform.position = GetPosition((TeleportLocation)location);
print("Teleporting Player to " + GetPosition((TeleportLocation)location));
}
}
}