Setup correct sizes and Quarry level switch
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using Pathfinding;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class FollowerController : MonoBehaviour
|
||||
{
|
||||
@@ -32,15 +33,29 @@ public class FollowerController : MonoBehaviour
|
||||
aiPath = GetComponent<AIPath>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
void OnEnable()
|
||||
{
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
FindPlayerReference();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
|
||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
FindPlayerReference();
|
||||
}
|
||||
|
||||
void FindPlayerReference()
|
||||
{
|
||||
// Find player by tag
|
||||
GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
|
||||
if (playerObj != null)
|
||||
{
|
||||
playerTransform = playerObj.transform;
|
||||
playerAIPath = playerObj.GetComponent<AIPath>();
|
||||
// Fetch player's max speed
|
||||
if (playerAIPath != null)
|
||||
{
|
||||
playerMaxSpeed = playerAIPath.maxSpeed;
|
||||
@@ -48,12 +63,25 @@ public class FollowerController : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("FollowerController: Player object with tag 'Player' not found.");
|
||||
playerTransform = null;
|
||||
playerAIPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
FindPlayerReference();
|
||||
}
|
||||
|
||||
void UpdateFollowTarget()
|
||||
{
|
||||
if (playerTransform == null)
|
||||
{
|
||||
// Try to reacquire reference if lost
|
||||
FindPlayerReference();
|
||||
if (playerTransform == null)
|
||||
return; // Still missing, skip update
|
||||
}
|
||||
// Determine direction: use player's velocity if available, else lastMoveDir
|
||||
Vector3 playerPos = playerTransform.position;
|
||||
Vector3 moveDir = Vector3.zero;
|
||||
@@ -81,7 +109,12 @@ public class FollowerController : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
if (playerTransform == null)
|
||||
return;
|
||||
{
|
||||
// Try to reacquire reference if lost
|
||||
FindPlayerReference();
|
||||
if (playerTransform == null)
|
||||
return; // Still missing, skip update
|
||||
}
|
||||
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= followUpdateInterval)
|
||||
|
||||
Reference in New Issue
Block a user