void Update() { modalPanel = ModalPanel.Instance(); displayManager = DisplayManager.Instance(); PlayerHealth playerHealth = FindObjectOfType <PlayerHealth>(); GameObject[] enemies = GameObject.FindGameObjectsWithTag("EnemyTank"); avg = 0; counter = 0; foreach (GameObject target in enemies) { if (target != null) { float distance = Vector3.Distance(target.transform.position, transform.position); EnemyAffiliation nme = target.GetComponent <EnemyAffiliation> (); if (nme != null) { affil1 = nme.affiliation1; affil2 = nme.affiliation2; if (distance < 10) { avg += affil1; avg -= affil2; counter++; } } } } if (counter != 0) { ChangeAffiliation(); if ((avg > 0) && (affiliation1 == 1)) { playerHealth.IncreaseHealth(); if (!functionCalled) { Invoke("urSafe", 4f); functionCalled = true; } } else if ((avg < 0) && (affiliation2 == 1)) { playerHealth.IncreaseHealth(); if (!functionCalled) { Invoke("urSafe", 4f); functionCalled = true; } } else { playerHealth.DecreaseHealth(0.2f); if (functionCalled) { Invoke("urNot", 1f); functionCalled = true; } } } else { playerHealth.DecreaseHealth(0.2f); if (functionCalled) { Invoke("urNot", 1f); functionCalled = true; } } altColor.r = affiliation1; altColor.g = 0; altColor.b = affiliation2; altColor.a = 1; //Assign the changed color to the material. rend.material.color = altColor; // bottom = this.gameObject.transform.GetChild(0).gameObject; // Renderer renderer = bottom.GetComponent<Renderer> (); // renderer.material.color = altColor; }
void OnTriggerEnter(Collider other) { modalPanel = ModalPanel.Instance(); displayManager = DisplayManager.Instance(); if (other.tag == "Player") { //Destroy(other.gameObject); PlayerAffiliation playerAffiliation = other.GetComponent <PlayerAffiliation> (); PlayerHealth playerHealth = other.GetComponent <PlayerHealth> (); EnemyAffiliation enemyAffiliation = GetComponent <EnemyAffiliation> (); if (playerAffiliation != null) { playerAff1 = playerAffiliation.affiliation1; playerAff2 = playerAffiliation.affiliation2; queCount = playerAffiliation.queCounter; } if (enemyAffiliation != null) { aff1 = enemyAffiliation.affiliation1; aff2 = enemyAffiliation.affiliation2; } if (playerHealth != null) { truth = playerHealth.truth; } if (truth > 0) { if (aff1 == 1) { modalPanel.Choice(dem [Random.Range(0, 6)]); playerHealth.DecreaseTruth(Random.Range(-10, 30)); if (aff1 != playerAff1) { playerHealth.DecreaseHealth(20); } } else if (aff2 == 1) { modalPanel.Choice(rep [Random.Range(0, 5)]); playerHealth.DecreaseTruth(Random.Range(-10, 30)); if (aff2 != playerAff2) { playerHealth.DecreaseHealth(20); } } else if (gameObject.tag == "Bullet") { modalPanel.Choice(que [queCount]); playerHealth.DecreaseTruth(Random.Range(-50, 0)); playerAffiliation.incQueCount(); } if (playerAffiliation != null) { playerAffiliation.functionCalled = false; } updated = true; } else { modalPanel.Choice("You don't seem to get to the truth. What if you abandon the group and ask questions?") } // if (playerHealth != null) { // // // } else { // Debug.LogWarning ("No PlayerHealth found on EnemyTank."); // } //Destroy (this.gameObject); } }