How to check for something to let an action happen?

Hi there,

I’m creating a video game right now. It’s a 3d ball scroller, and I want it so that once I pick up something (a bar of soap in this case), my ball texture changes. This is already done, but I also want it to be that once my texture is changed, I’ll be able to destroy another game object.
So lets say I picked up the soap bar, and then I can destroy a virus simply by rolling over it, but ONLY if I have picked up the soap bar.
Right now, it always destroys the virus, no matter nor I’ve picked up the soap bar or not.

My scripts are:

The soap bar:

#pragma strict
var coinEffect : Transform; 
var coinValue = 1; 
var Soap : Texture2D; 
var TheBall : Transform;

function OnTriggerEnter (info : Collider) 
{ 
	if (info.tag == "Player") 
	{ 
		GameMaster.currentScore += coinValue; 
		var effect = Instantiate(coinEffect, transform.position, transform.rotation); 
		Destroy(effect.gameObject, 3); 
		Destroy(gameObject); 
		TheBall.renderer.material.mainTexture = Soap; 
	} 
}

The virus:

#pragma strict
var coinValue = 1; 
var TheBall : Transform;

function OnTriggerEnter (info : Collider) { 
	if (info.tag == "Player") 
	{ 
		GameMaster.currentScore += coinValue; 
		var effect = Instantiate(coinEffect, transform.position, transform.rotation); 
		Destroy(effect.gameObject, 3); 
		Destroy(gameObject); 
	} 
}

So what do I have to add to make it so that I can only destroy the virus once I have picked up the soap?

I’d probably restructure your logic so that you have one script for the ball/player.

The logic would be something like:

if I collided with something:
    was it a soap bar?:
        if yes, change texture to soap 
    was it a virus?
        if so, am I already soap? 
             if yes, kill the virus
             if no, too bad, can't to anything

That way, when you want to add more items, you won’t have to add new scripts every time (although you could have more scripts that do specific things when you collide with those type of objects)

That script would live on the player, then you could either look at the collider’s name or tag to decide what thing you hit. You could also create a variable of type boolean to save whether you hit the soap or not:

    var isSoapy : boolean;
    
    
    function Start()
    {
       isSoapy = false;
    }
    
    function OnTriggerEnter (info : Collider) 
    { 
        if (info.tag == "Soap") 
        {
             isSoapy = true;
        }
    
        if (info.tag == "Virus")
        {
            if(isSoapy ==true) //could also write if(isSoapy)
            {
               //kill the virus
            }
        }

   }