Skip to content
Snippets Groups Projects
Commit e3529ed4 authored by Michal Černý's avatar Michal Černý :fog:
Browse files

add scene reset on catch

parent 7e88dca1
No related branches found
No related tags found
No related merge requests found
Pipeline #233773 passed
......@@ -403,7 +403,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4dcff51e92fd89849bb7c3ae299cd18f, type: 3}
m_Name:
m_EditorClassIdentifier:
speedMultiplier: 2
speedMultiplier: 3
catchDistance: 1
--- !u!206 &5938277610741420704
BlendTree:
m_ObjectHideFlags: 1
......
......@@ -2,18 +2,18 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;
 
public class ChasingBehaviour : StateMachineBehaviour {
[SerializeField] private float speedMultiplier = 2f;
[SerializeField] private float speedMultiplier = 3f;
[SerializeField] private float catchDistance = 1f;
 
private Rigidbody rigidbody;
private NavMeshAgent navMeshAgent;
private ObjectInView playerInView;
 
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (rigidbody is null) {
rigidbody = animator.GetComponentInParent<Rigidbody>();
if (navMeshAgent is null) {
navMeshAgent = animator.GetComponentInParent<NavMeshAgent>();
playerInView = animator.GetComponentInParent<ObjectInView>();
}
......@@ -28,6 +28,11 @@ override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (NavMeshUtils.AgentArrivedOrGaveUp(navMeshAgent))
animator.SetBool("chasing", false);
if (Vector3.Distance(playerInView.targetCollider.bounds.center, playerInView.collider.bounds.center) <= catchDistance) {
Debug.Log("CAUGHT!");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
 
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
......
......@@ -4,7 +4,7 @@
using UnityEngine;
 
public class ObjectInView : MonoBehaviour {
[SerializeField] private GameObject target;
[SerializeField] public GameObject target; // pls dont actually set :)
[SerializeField, Range(0, 360)] private float fieldOfView = 100f;
[SerializeField] private LayerMask obstacleMask;
[SerializeField, Range(0, 2)] private float eyeLevel = 1.46f;
......@@ -15,8 +15,8 @@ public class ObjectInView : MonoBehaviour {
public float lastSeenTime { get; private set; } = 0;
public event Action<ObjectInView> OnVisible;
 
private new Collider collider;
private Collider targetCollider;
public new Collider collider { get; private set; }
public Collider targetCollider { get; private set; }
 
private void Awake() {
collider = GetComponent<Collider>();
......
......@@ -1219,14 +1219,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1778908717}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: -8.454, y: 1.037, z: 1.008}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0}
--- !u!114 &1778908722
MonoBehaviour:
m_ObjectHideFlags: 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment