void Awake() { Player = GameObject.FindWithTag("Player"); playerLevel = Player.GetComponent <PlayerLevel> (); anim = GetComponent <Animator> (); currentHealth = startingHealth; followscript = GetComponent <AI1> (); ooh = GetComponent <AudioSource> (); }
void OnCollisionEnter(Collision collision) { Enemy e = collision.gameObject.GetComponent <Enemy>(); // if hit enemy AI1 teamMember = collision.gameObject.GetComponent <AI1>(); // if hit teammate Flag f = collision.gameObject.GetComponent <Flag>(); // if hit flag AIHome win = collision.gameObject.GetComponent <AIHome>(); // if hit the homemark if (f) // if he hit the flag, set boolen hasflag to true { hasFlag = true; target = home.gameObject; // make him go back to home area Align(); } if (win && hasFlag == true) { gameOverCanvas.SetActive(true); Debug.Log("win"); } if (e && transform.position.z > 300) // if outside of home positoin { GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; // freeze if hit GetComponent <Rigidbody>().velocity = new Vector3(0.0f, 0.0f, 0.0f); frozen = true; stopSteeringArrive = true; if (hasFlag == true) { hasFlag = false; flag.returnToHomeSpot(); // return flag to original position } } if (e && transform.position.z <= 299) // if hitting enemy in home zone { if (target != flag.gameObject) { // Wander(); // continue wandering wanderMove = true; wanderOn = true; targetCaught = true; // caught enemy target Debug.Log("AI Target: " + target); } } if (teamMember && frozen == true) // if hit by teammate and are currently frozen { frozen = false; // unfreeze teammate stopSteeringArrive = false; // allow steering arrive to move characters GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; // unfreeze GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; // keep rotation frozen teamMember.SetTargetToNull(); // remove teammates target teamMember.SetWanderBool(true); // set wandering to true, make him wander again } }
void OnCollisionEnter(Collision collision) { Enemy teamMember = collision.gameObject.GetComponent <Enemy>(); AI1 enemies = collision.gameObject.GetComponent <AI1>(); Flag f = collision.gameObject.GetComponent <Flag>(); EnemyHome win = collision.gameObject.GetComponent <EnemyHome>(); if (f) { hasFlag = true; target = home.gameObject; Align(); } if (win && hasFlag == true) { gameOverCanvas.SetActive(true); } if (enemies && transform.position.z <= 299) { GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; GetComponent <Rigidbody>().velocity = new Vector3(0.0f, 0.0f, 0.0f); frozen = true; stopSteeringArrive = true; if (hasFlag == true) { hasFlag = false; flag.returnToHomeSpot(); } } if (enemies && transform.position.z > 300) { if (target != flag.gameObject) { Wander(); targetCaught = true; Debug.Log("enemy target: " + target); } } if (teamMember && frozen == true) { frozen = false; // unfreeze teammate stopSteeringArrive = false; // allow steering arrive to move characters GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; // unfreeze GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; // keep rotation frozen teamMember.SetTargetToNull(); // remove teammates target teamMember.SetWanderBool(true); // set wandering to true, make him wander again } }
void OnCollisionEnter(Collision collision) { AI1 aiCharacter = collision.gameObject.GetComponent <AI1>(); Enemy enemy = collision.gameObject.GetComponent <Enemy>(); if (aiCharacter && aiCharacter.GetTarget() == true && gameObject.tag == "F1") // if flag 1 hit by ai, assign flag to ai character. { transform.parent = aiCharacter.transform; transform.position = new Vector3(aiCharacter.transform.position.x, aiCharacter.transform.position.y, aiCharacter.transform.position.z); //Object.Destroy(GetComponent<Rigidbody>()); } if (enemy && enemy.GetTarget() == true && gameObject.tag == "F2") // if flag 2 hit by enemy, assign flag to enemy character. { transform.parent = enemy.transform; transform.position = new Vector3(enemy.transform.position.x, enemy.transform.position.y, enemy.transform.position.z + 0.5f); } }
void Start() { childComponent = transform.GetChild(0).gameObject; // get first child object Renderer rend = childComponent.GetComponent <Renderer>(); rend.material.shader = Shader.Find("Specular"); rend.material.SetColor("_SpecColor", Color.yellow); Wander(); decider = GameObject.Find("Controller").GetComponent <Controller>(); flagGetter = decider.GetAIDecider(); flag = GameObject.Find("Flag1").GetComponent <Flag>(); home = GameObject.Find("AIHome").GetComponent <AIHome>(); if (gameObject.tag == "A1") { teamMate = GameObject.Find("A2").GetComponent <AI1>(); } if (gameObject.tag == "A2") { teamMate = GameObject.Find("A1").GetComponent <AI1>(); } }