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 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>(); } }