Question by
SuperCrow2 · Jun 03, 2020 at 10:58 PM ·
script.unity 2dgamecolor changec #
Player is not changing color from hitting enemy
I got it to change when you fall into a pit, but with the enemy, they are moving, idk if thats making it not work or not. When you hit an enemy you are supposed to change color but you dont.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangingColor : MonoBehaviour
{
//change color to white when enemy hits you
private Renderer rend;
private Color colorToTurnTo = Color.white;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
other.GetComponent<Renderer>().material.color = colorToTurnTo;
}
}
public void ChangeColor()
{
rend.material.color = colorToTurnTo;
}
}
Comment