// Update is called once per frame void Update() { GameObject Grunt = GameObject.Find("grunt"); GruntController gruntController = Grunt.GetComponent <GruntController> (); if (gruntController._UnitSelected == true) { _PortalSelected = false; if (highlightTracker == false) { DestroyHighlight(); } } AdjustCurrentHealth(0); if (highlight == true && highlightTracker == false) { highlightTracker = true; if (_PortalSelected == false) { HighlightSelection(); } } if (Input.GetButtonDown("mouseScrollLock")) { if (_PortalSelected == true) { _PortalSelected = false; DestroyHighlight(); } } }
/// <summary> /// Sent each frame where a collider on another object is touching /// this object's collider (2D physics only). /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> void OnCollisionStay2D(Collision2D other) { if (other.transform.tag.Equals("Grunt")) { if (animator.GetBool("Punching")) { animator.SetBool("Punching", false); //set punching state to false otherwise while collision stays health is reduced continually on a single punch GruntController script = other.gameObject.GetComponent <GruntController>(); script.Health = HealthController.ReduceHealth(damageMelee, script.Health); } } }
/// <summary> /// Sent when an incoming collider makes contact with this object's /// collider (2D physics only). /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> void OnCollisionEnter2D(Collision2D other) { if (other.transform.tag.Equals("BulletStopper")) { Destroy(gameObject); } if (other.transform.tag.Equals("Grunt")) { GruntController script = other.gameObject.GetComponent <GruntController>(); script.Health = HealthController.ReduceHealth(damage, script.Health); Destroy(gameObject); } }
void Shoot(GameObject target) { if (target != null) { //Accuracy calculations Vector3 deviation3D = Random.insideUnitCircle * leader.accuracy; Quaternion rot = Quaternion.LookRotation(Vector3.forward + deviation3D); Vector3 fwd = leader.transform.rotation * rot * Vector3.forward; //Shooting ray RaycastHit hit; Debug.DrawRay(leader.transform.position, fwd * 100, Color.red, 0.5f); if (Physics.Raycast(leader.transform.position, fwd, out hit, 100)) { if (hit.transform.tag == leader.enemyTag) { if (hit.transform.GetComponent <StatePatternLeader>()) //if target is a leader { StatePatternLeader enemyLeader = hit.transform.GetComponent <StatePatternLeader>(); enemyLeader.health -= 25; if (enemyLeader.health < 1) { leader.RemoveEnemyLeader(enemyLeader); } } else if (hit.transform.GetComponent <GruntController>()) //if target is a grunt { GruntController enemyGrunt = hit.transform.GetComponent <GruntController>(); enemyGrunt.health -= 25; if (enemyGrunt.health < 1) { leader.RemoveEnemyGrunt(enemyGrunt); } } } } } leader.AnimTimer(1, "ShootAnim"); }
private void Awake() { gruntController = GameObject.FindGameObjectWithTag("GruntTag").GetComponent <GruntController>(); inputManager3D = GameObject.FindGameObjectWithTag("Player").GetComponent <InputManager3D>(); }
public void RemoveEnemyGrunt(GruntController removee) { enemies.Remove(removee.GetComponent <Collider>()); UpdateGruntEnemyLists(removee.GetComponent <Collider>()); removee.Die(); }
void Shoot() { if (shootTarget != null) { //Accuracy calculations Vector3 deviation3D = Random.insideUnitCircle * accuracy; Quaternion rot = Quaternion.LookRotation(Vector3.forward + deviation3D); Vector3 fwd = transform.rotation * rot * Vector3.forward; //Shooting ray RaycastHit hit; Debug.DrawRay(transform.position, fwd * 100, Color.red, 0.5f); if (Physics.Raycast(transform.position, fwd, out hit, 100)) { if (hit.transform.tag == enemyTag) { if (hit.transform.GetComponent <StatePatternLeader>()) //if target is a leader { StatePatternLeader enemyLeader = hit.transform.GetComponent <StatePatternLeader>(); enemyLeader.health -= 10; if (enemyLeader.health < 1) { if (currentLeader != null) { currentLeader.RemoveEnemyLeader(enemyLeader); } else { if (enemyLeader != null) { enemyList.Remove(enemyLeader.GetComponent <Collider>()); enemyLeader.Die(); } } } } else if (hit.transform.GetComponent <GruntController>()) //if target is a grunt { GruntController enemyGrunt = hit.transform.GetComponent <GruntController>(); enemyGrunt.health -= 10; if (enemyGrunt.health < 1) { if (currentLeader != null && enemyList.Contains(enemyGrunt.GetComponent <Collider>())) { currentLeader.RemoveEnemyGrunt(enemyGrunt); } else { if (enemyGrunt != null) { enemyList.Remove(enemyGrunt.GetComponent <Collider>()); enemyGrunt.Die(); } } } } } } } nextShootTime = Time.time + 1; }