My objective is this: When objectA enters the objectBs collider (objectA CAN penetrate objectB), the tag of objectA changes or not, depending on objectAs current tag. This is accomplished by a script attached to objectB (the comments are what I EXPECTED the script to do):
var tagChangeNA: GameObject; // sound played when the tag change is NOT possible
var tagChanged: GameObject; // sound played when the tag change IS possible
function OnTriggerEnter (col: Collider) { //the following will be done when objectA enters object Bs collider
if (col.gameObject.tag == "Cold"){ //if objectAs tag is Cold...
Instantiate(tagChanged); // play this sound
col.gameObject.tag = "Medium"; //change the objectAs tag to Medium
Destroy(gameObject); //destroy objectB
}
if (col.gameObject.tag == "Medium"){
Instantiate(tagChanged); // play this sound
col.gameObject.tag = "Hot"; //change the objectAs tag to Hot
Destroy(gameObject); //destroy objectB
}
if (col.gameObject.tag !="Cold" || col.gameObject.tag !="Medium"){ //if the objectAs tag is something else...
Instantiate(tagChangeNA); // actually dont do anything. Only play this sound.
}
}
THIS SCRIPT DOES NOT WORK AS EXPECTED. What happens is:
I control objectA to enter objectBs collider.
The initial tag of objectA is "Cold".
When I enter objectB, objectB gets destroyed NO MATTER WHAT objectA's TAG IS (EVEN COMPLETELY IRRELEVANT TAGS)
Both sounds are instantiated (tagChanged & tagChangedNA) simultaneously.
objectAs tag DOES NOT CHANGE.
I really cannot understand why it works in this crazy way.
What am I missing here?
NOTE: both objects are Prefabs, they have Rigid Body component attached and the tags mentioned are already defined in the tags list.