I am making a Unity Playground platformer based on Player changing colour (changing a character for a different colour) and I want to make certain terrains to kill every other colour than the “right” one.
I tried to modify an existing script (ModifyHealthAttribute) to look for a yellow player but it kills it no matter if yellow or not.
Can you help?
using UnityEngine;
using System.Collections;
[AddComponentMenu(“Playground/Attributes/Modify Health”)]
public class ModifyHealthAttributeElectric : MonoBehaviour
{
public bool destroyWhenActivated = false;
public int healthChange = -1;
private void Reset()
{
Utils.Collider2DDialogWindow(this.gameObject, true);
}
private void OnCollisionEnter2D(Collision2D collisionData)
{
if (collisionData.collider.name == "Electric")
{
//Don't kill a Player
}
else
{ OnTriggerEnter2D(collisionData.collider); }
}
private void OnTriggerEnter2D(Collider2D colliderData)
{
HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent<HealthSystemAttribute>();
if (healthScript != null)
{
// subtract health from the player
healthScript.ModifyHealth(healthChange);
if (destroyWhenActivated)
{
Destroy(this.gameObject);
}
}
}
}