// Update is called once per frame void Update() { BasicEnemyController enemyController = this.gameObject.GetComponent <BasicEnemyController>(); NavMeshAgent meshAgent = this.gameObject.GetComponent <NavMeshAgent>(); meshAgent.speed = this.EnemyPrimaryMovementDictionary[enemyController.ePrimaryMovementState]; meshAgent.angularSpeed = this.EnemySecondaryMovementDictionary[enemyController.eSecondaryMovementState]; }
private void OnTriggerEnter2D(Collider2D hitInfo) { BasicEnemyController enemy = hitInfo.GetComponentInParent <BasicEnemyController>(); if (enemy != null) { attackDetails[0] = 1f; attackDetails[1] = transform.position.x; enemy.Damage(attackDetails); } Debug.Log(hitInfo.name); Destroy(gameObject); }
// Update is called once per frame void Update() { BasicEnemyController enemyController = this.gameObject.GetComponent <BasicEnemyController>(); if (enemyController.canGoToPrimaryTarget) { InputHandler.HandleMovementInputTargeted(this.gameObject, this.axisVVal, this.isRunning, enemyController.PrimaryTarget); this.angleInDegreesToTarget = InputHandler.HandleRotationInputTargeted(this.gameObject, enemyController.PrimaryTarget); } else { ScriptedGoalHandler goalHandler = this.gameObject.GetComponent <ScriptedGoalHandler>(); InputHandler.HandleMovementInputTargeted(this.gameObject, this.axisVVal, this.isRunning, goalHandler.Goals[goalHandler.currentGoalIndex]); this.angleInDegreesToTarget = InputHandler.HandleRotationInputTargeted(this.gameObject, goalHandler.Goals[goalHandler.currentGoalIndex]); } }
// Update is called once per frame void Update() { ScriptedGoalHandler goalHandler = this.gameObject.GetComponent <ScriptedGoalHandler>(); if (goalHandler == null) { return; } BasicEnemyController enemyController = this.gameObject.GetComponent <BasicEnemyController>(); if (enemyController.canGoToPrimaryTarget) { currGoal = enemyController.PrimaryTarget.transform.position; } else { currGoal = goalHandler.Goals[goalHandler.currentGoalIndex]; } navAgent.destination = currGoal; //Debug.DrawRay(this.transform.position, this.transform.forward * this.forwardMagnitude); }
// Start is called before the first frame update void Start() { enemyController = gameObject.GetComponent <BasicEnemyController>(); r2 = gameObject.GetComponent <Rigidbody2D>(); }
void Update() { //Check if any enemies in range if (targets.Count != 0) //Active state { var distance = float.MaxValue; GameObject target = null; //Remove any dead enemies targets = targets.Where(item => item != null).ToList(); //Loop through possible targets and find the closest foreach (var i in targets) { var diff = i.transform.position - transform.position; var curDistance = diff.sqrMagnitude; if (curDistance < distance) { target = i; distance = curDistance; } } if (target == null) { return; } //Rotate to face target var lookPos = target.transform.position - transform.position; lookPos.y = 0; var endRot = Quaternion.LookRotation(lookPos); var newRot = Quaternion.RotateTowards(transform.rotation, endRot, Time.deltaTime * rotationSpeed); transform.rotation = newRot; //Fire every rateOfFire seconds, but only if enemy is in our sights timer += Time.deltaTime; if (Vector3.Angle(transform.forward, lookPos) < maxFireAngle && timer > rateOfFire) { //Shoot out our raycast and apply damage to enemy StartCoroutine(ShotEffect()); RaycastHit hit; shotLine.SetPosition(0, transform.InverseTransformPoint(barrelExit.position)); if (Physics.Raycast(barrelExit.position, transform.forward, out hit, range)) { shotLine.SetPosition(1, transform.InverseTransformPoint(hit.point)); BasicEnemyController health = hit.collider.GetComponent <BasicEnemyController>(); //Debug.Log("hit " + hit.collider.gameObject.name); if (health != null) { health.Damage(damage, gameObject); } } else { shotLine.SetPosition(1, transform.InverseTransformPoint(transform.forward * range)); } timer = 0f; } } else //Idle state { //transform.Rotate(0f, 0.1f, 0f, Space.Self); } }
void Start() { ec = this.GetComponentInParent <BasicEnemyController>(); seeker = GetComponent <Seeker>(); rb = GetComponent <Rigidbody2D>(); }