//to identify who has been hit by cannonball. - Aadi. //Uses the OnTriggerEnter method to check if the "other" gameobject has a PirateShipController, if yes than gets the PirateShipController component of that gameobject and gives the "newDamage" integer as the new parameter for the TakeDamage(int damage) method in the PirateShipController and finally destroys the gameobject which is using the 'CannonBall'script. - Aadi. public void OnTriggerEnter(Collider other) { if (other.gameObject.GetComponent <PirateShipController>()) { PirateShipController pirateShipController = other.gameObject.GetComponent <PirateShipController>(); //Debug.Log("Been hit by Cannonball"); pirateShipController.TakeDamage(newDamage); Destroy(this.gameObject); } }
// Start is called before the first frame update void Start() { BaseAI[] aiArray = new BaseAI[] { new IljaAI(), new PondAI(), new PondAI(), new PondAI() }; for (int i = 0; i < 4; i++) { GameObject pirateShip = Instantiate(PirateShipPrefab, SpawnPoints[i].position, SpawnPoints[i].rotation); PirateShipController pirateShipController = pirateShip.GetComponent <PirateShipController>(); pirateShipController.SetAI(aiArray[i]); pirateShips.Add(pirateShipController); } }
// Start is called before the first frame update void Start() { //moved the aiArray list command to outside. - Aadi. //changed the integer value of greater than i from 4 to 5. - Aadi. //Increased the size for Spawn Points section in Inspector Window. - Aadi. //Cloned the spawnpoint5 from spawnpoint4 and dragndropped it to Element 4. - Aadi. for (int i = 0; i < 5; i++) { GameObject pirateShip = Instantiate(PirateShipPrefab, SpawnPoints[i].position, SpawnPoints[i].rotation); PirateShipController pirateShipController = pirateShip.GetComponent <PirateShipController>(); pirateShipController.SetAI(aiArray[i]); pirateShips.Add(pirateShipController); if (i == 0) { pirateShip.name = "Aadi"; pirateShipController.cannonballs += 100; //pirateShip.AddComponent<PirateShipController>().PerkOne(); } if (i == 1) { //pirateShip.AddComponent<PirateShipController>().PerkTwo(); pirateShip.name = "Ruben"; } if (i == 2) { //pirateShip.AddComponent<PirateShipController>().PerkThree(); pirateShip.name = "Maxym"; } if (i == 3) { //pirateShip.AddComponent<PirateShipController>().PerkFour(); pirateShip.name = "Martin"; } if (i == 4) { //pirateShip.AddComponent<PirateShipController>().PerkFive(); pirateShip.name = "Sjoeke"; } } }