Hello guys,
It’s me again still working on that Brackeys tutorial, but after sorting through the shooting problems and the respawning not working at all until I reworked the code, I am now working on getting damage to work between objects and having problems getting it to register.
The code with the collision between the bullet and AlienShip at the moment registers and shows damage only for one hit, so, I am hoping that one of you knowledgeable guys might be able to point me in the right direction :).
In any case any assistance will be greatly appreciated!
The code is as follows, just forget about how inefficient the code is
:
using UnityEngine;
using System.Collections;
public class BulletCollision : MonoBehaviour {
//link to the explosion prefab: Explosion_prefab
public Transform xplosionPrefab;
//link to EnemyMaster Script
EnemyMaster enemyShip = new EnemyMaster() ;
public int damageAmount = 20;
//Hell, I hate the way MonoDevelop indents the code
void OnCollisionEnter2D (Collision2D col) {
print ("BulletCollision.cs");
if (col.gameObject.tag == "Sphere") {
print ("The bullet hit the SPHERE.......");
}
if (col.gameObject.tag == "Platform") {
//make xplosion work on Platform objects for now
//until I find a way to make the bullet pass thru the
//platforms without needing to make an Xplosion occur
//AND put it on all needed object without copying code
//probably just use: if ( (col.obj.tag == blah) OR (col.obj.tab==blah) ) { }
//use explosion code between braces
ContactPoint2D contact = col.contacts [0];
Quaternion rot = Quaternion.FromToRotation (Vector3.up, contact.normal);
Vector3 pos = contact.point;
Instantiate (xplosionPrefab, pos,rot);
print ("The bullet hit the PLATFORM........");
//destroy the gameObject because the bullet/missile has run it's course
Destroy (gameObject);
}
if (col.gameObject.tag == "AlienShip") {
//make explosion occur on AlienShip
ContactPoint2D contact = col.contacts [0];
Quaternion rot = Quaternion.FromToRotation (Vector3.up, contact.normal);
Vector3 pos = contact.point;
Instantiate (xplosionPrefab, pos,rot);
//destroy this gameobject
//"this" being the prefab it is attached to - MissileGroup.
Destroy (gameObject);
enemyShip.EnemyDamage(damageAmount);
print ("bullet hit the ALIENSHIP. Health: "+enemyShip.GetHealth() );
}
//end those if's :)
}//end OnCollisionEnter(col col)*/
}//end BulletCollision class()