Triggering a Transform to Active on Collision

I’m a complete noob when it comes to scripting, and am having difficulty in triggering one of four different objects upon collision.

Long story short, I’m creating a card game where players place cards in a cauldron. The cauldron displays one of four ‘elemental states’, which the players change with whatever value is attached to the card they play when it lands in the cauldron.

I have the ‘elementEffects’ in an array (they need to be; it’s part of my assessment), and they are all set to inactive in Unity.

2 things I need help with:

1 - I’m not sure how declare the ‘collider’ variable, as the cards are varied
2 - How to switch one effect off and the next one on with the next collision

Code attached to the Cauldron follows (nb: elementEffects is ‘i-1’ as the CardSuits are numbered 1 to 4, not 0 to 3):

var elementEffects : Transform[];

function OnCollisionEnter(collision : Collision) 
{
	var i = collider.GetComponent(CardValue).cardSuit;
	elementEffects[i-1].active = true;	 
}

Thanks heaps in advance!

You can access the correct collider by using collision.collider. You don’t really need a ‘collider’ variable, unless I’m misunderstanding you.

To set them from active to inactive when another collision is made, I would personally loop through all elementEffects and set them all to inactive, and then set the correct one to active every time a collision is made. This should ensure the desired effect (no pun intended). The other option is to store a variable which stores the last elementEffect that was set to active so you can directly set it to inactive, and then assign the new elementEffect to that variable.

So your script would change to:

var elementEffects : Transform[];
 
function OnCollisionEnter(collision : Collision) 
{
    DeactivateElementEffects();
    var i = collision.collider.GetComponent(CardValue).cardSuit;
    elementEffects[i-1].active = true;  
}

private void DeactivateElementEffects()
{
    for (var i = 0; i < elementEffects.length; i++)
    {
        elementEffects*.active = false;*

}
}
Or:
var activeEffect : Transform;
var elementEffects : Transform[];

function OnCollisionEnter(collision : Collision)
{
var i = collision.collider.GetComponent(CardValue).cardSuit;
activeEffect.active = false;
activeEffect = elementEffects[i-1];
elementEffects[i-1].active = true;
}
I haven’t tested this code and since I usually use C# it may be incorrect, but you should get the idea.