private void Awake() { player = GameObject.FindGameObjectWithTag("Player"); Assert.IsNotNull(player, "Failed to locate GameObject with tag <b>Player</b>"); agent = GetComponent <NavMeshAgent>(); Assert.IsNotNull(agent, "Failed to locate <b>NavMeshAgent</b> on Enemy GameObject"); stateMachine = GetComponent <ChickenStateMachine>(); Assert.IsNotNull(stateMachine, "Failed to locate <b>ChickenStateMachine.cs</b> on Enemy GameObject"); perceptionScript = GetComponent <AIPerception>(); Assert.IsNotNull(perceptionScript, "Failed to locate <b>AIPerception.cs</b> on Enemy GameObject"); playerLightComponent = player.GetComponent <LightComponent>(); Assert.IsNotNull(playerLightComponent, "Failed to locate <b>LightComponent.cs</b> on Player GameObject"); playerCombatComponent = player.GetComponent <CombatComponent>(); Assert.IsNotNull(playerCombatComponent, "Failed to locate <b>CombatComponent.cs</b> on Player GameObject"); lightBombs = GameObject.FindGameObjectsWithTag("LightBomb"); Assert.IsNotNull(lightBombs, "Failed to locate <b>LightBombs</b> in array check in Enemy GameObject"); gameManager = player.GetComponent <GameManagerComponent>(); Assert.IsNotNull(gameManager, "Failed to locate <b>GameManagerComponent.cs</b> on Player GameObject"); world = GameObject.FindGameObjectWithTag("World"); Assert.IsNotNull(world, "Failed to locate <b>World</b> under Main scene in hierarchy"); worldSystem = world.GetComponent <World>(); Assert.IsNotNull(worldSystem, "Failed to locate <b>World.cs</b> on World GameObject"); originalWaitTime = waitTime; originalHuntTime = huntTime; originalAttackCooldown = attackCooldown; originalWalkSpeed = agent.speed; originalChargeSpeed = chargeSpeed; }
private void Awake() { for (int i = 0; i < InitialReactionConfig.Length; i++) { ReactionConfigs.Add(InitialReactionConfig[i].stimulus, InitialReactionConfig[i].reaction); } if (brain == null) { brain = GetComponent <AI_Base>(); } if (perception == null) { perception = GetComponentInChildren <AIPerception>(); } perception.NewCharacterEnterEvent += OnNewCharacterEnter; }
private void OnSceneGUI() { if (!target) { return; } Color oldColor = Handles.color; AIPerception perception = target as AIPerception; float halfFOV = perception.fovAngle * 0.5f; float coneDir = -90f; Quaternion leftRayRotation = Quaternion.AngleAxis(-halfFOV + coneDir, Vector3.up); Quaternion rightRayRotation = Quaternion.AngleAxis(halfFOV + coneDir, Vector3.up); Vector3 leftRayDir = leftRayRotation * perception.transform.right * perception.perceptionRadius; Vector3 rightRayDir = rightRayRotation * perception.transform.right * perception.perceptionRadius; arcHandle.angle = perception.fovAngle; arcHandle.radius = perception.perceptionRadius; Vector3 handleDir = leftRayDir; Vector3 handleNormal = Vector3.Cross(handleDir, perception.transform.forward); Matrix4x4 handleMatrix = Matrix4x4.TRS( perception.transform.position, Quaternion.LookRotation(handleDir, handleNormal), Vector3.one); using (new Handles.DrawingScope(handleMatrix)) { EditorGUI.BeginChangeCheck(); arcHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(perception, "Changed perception properties"); perception.fovAngle = Mathf.Clamp(arcHandle.angle, 0f, 359f); perception.perceptionRadius = Mathf.Max(arcHandle.radius, 1f); } } Handles.color = new Color(1f, 0f, 0f, 0.15f); Handles.DrawSolidArc(perception.transform.position, Vector3.up, rightRayDir, 360f - perception.fovAngle, perception.perceptionRadius); Handles.color = oldColor; }
void Start() { droneMoveSource = AudioHelper.CreateAudioSource(gameObject, droneMoveAudio); droneAlertSource = AudioHelper.CreateAudioSource(gameObject, droneAlertAudio); dronePursuitSource = AudioHelper.CreateAudioSource(gameObject, dronePursuitAudio); // Keep references to commonly accessed components. agent = GetComponent <NavMeshAgent>(); perception = GetComponentInChildren <AIPerception>(); // By default, the agent starts in the patrol state. perception.SetViewConeColor(normalColor); state = State.Patrol; // Track the agent's move speed. speed = agent.speed; // Store the list of waypoints from our patrol path. waypoints = new Transform[patrolPath.childCount]; for (int i = 0; i < waypoints.Length; ++i) { waypoints[i] = patrolPath.GetChild(i); } // Loop through all the waypoints and pick the closest one. This is where // we should patrol toward first. float closestDistance = Vector3.Distance(transform.position, waypoints[0].position); for (int i = 1; i < waypoints.Length; ++i) { float distance = Vector3.Distance(transform.position, waypoints[i].position); if (distance < closestDistance) { closestDistance = distance; currentWaypoint = i; } } // Hide the alert icon by default. exclamationMark.SetActive(false); }
private void OnDestroy() { AIPerception.UnregisterTarget(this); }
private void Awake() { m_attackingEnemies = new List <GameObject>(); AIPerception.RegisterTarget(this); }
public override void ActionStart(AI_Mission_Base mission, AI_Base brain, Character_Base character) { base.ActionStart(mission, brain, character); perception = character.GetComponentInChildren <AIPerception>(); Character = character; }
void Start() { droneMoveSource = AudioHelper.CreateAudioSource(gameObject, droneMoveAudio); droneAlertSource = AudioHelper.CreateAudioSource(gameObject, droneAlertAudio); dronePursuitSource = AudioHelper.CreateAudioSource(gameObject, dronePursuitAudio); // Keep references to commonly accessed components. agent = GetComponent<NavMeshAgent>(); perception = GetComponentInChildren<AIPerception>(); // By default, the agent starts in the patrol state. perception.SetViewConeColor(normalColor); state = State.Patrol; // Track the agent's move speed. speed = agent.speed; // Store the list of waypoints from our patrol path. waypoints = new Transform[patrolPath.childCount]; for (int i = 0; i < waypoints.Length; ++i) { waypoints[i] = patrolPath.GetChild(i); } // Loop through all the waypoints and pick the closest one. This is where // we should patrol toward first. float closestDistance = Vector3.Distance(transform.position, waypoints[0].position); for (int i = 1; i < waypoints.Length; ++i) { float distance = Vector3.Distance(transform.position, waypoints[i].position); if (distance < closestDistance) { closestDistance = distance; currentWaypoint = i; } } // Hide the alert icon by default. exclamationMark.SetActive(false); }