How to get a trigger to identify a prefab clone

What’s up everyone Rio here and I have this issue, I have a enemy character that I want to identify anything that’s being shot at it from the player, problem is when the player shoot, the first bulletcase is bulletcase then each one after that’s fired is bulletcase(clone) the script will decrease the enemy health from the original bulletcase if input only bulletcase as the identifier in the trigger code but will not decrease anymore because each BC after that is BC(clone) and unity couldn’t work with me putting in bulletCase(Clone) because of the parentheses this I s what I tried

var health1 : int;
var Player : GameObject;



private var deathTime : float;
private var alive : boolean = true;

function Update(){
	if( health1 <= 0  alive){
		alive = false;
		deathTime = Time.time;
	}
	if (health1 > 0){
		alive = true;
	}
	health1 = Mathf.Max(health1, 0);
     
     if(health1 <=0) {
			Destroy(gameObject);
			GameObject.Find("xpText").GetComponent("LevelUp").curXp += 10;
			GameObject.FindGameObjectWithTag("Player").GetComponent("MoneySystem").curMoney +=100;
			
     }
}


function OnTriggerEnter (bulletCase  bulletCase(Clone) : Collider) {
			health1 --;

		}

can anyone help me out with this issue or recommend a solution

You really need to learn some basics of coding…

Anyway:

function OnTriggerEnter (bulletCase  bulletCase(Clone) : Collider) {
            health1 --;
        }

is totally wrong… should be something like:

function OnTriggerEnter (other : Collider) {
if(other.name == "bulletCase(Clone)" ) {


            health1 --;
     }
}

Hey Rio!

You seem to be a little confused about method parameters on the method OnTriggerEnter().

The method OnTriggerEnter() can have a Collider parameter that will be assigned when unity’s internal code calls it.

Your code should follow the suit of:

function OnTriggerEnter(col : Collider){
      if(col.gameObject.name == "bulletCase" || col.gameObject.name == "bulletCase(Clone)"){
             healthl--;
}
}

Now when a collision happens on the gameObject (that registers in the collision matrix) Unity will call the method and set the Collider, col; col now holds the Collider that has hit our gameObject. Next, we need to check if the collider’s gameObject is named “bulletCase” OR(||) “bulletCase(Clone)” and if so we subtract health.

A different way to do this would to rename the Instantiated object:

 GameObject GO = Instatiate(bulletPrefab, xxxxxx, xxxxxxx,xxxxxxx); GO.name = "bulletCase";

Now all the bullets spawned in that line of code will be renamed to “bulletCase”; that way you can drop the second half of the above if statement.

Cheers Landon.

Thanks a lot yet for some reason or another it’s not working at all now after I tried both scripts any more suggestions and I am working to increase my skill set with programming I have some understanding but not enough yet to where I don’t have to ask for help
thou when I do I will be helping others,
RIO

You could give it a tag and then just use CompareTag:

Use CompareTag whenever possible because it’s optimized for game speed.