I think i did the same as the tutorial to change the sprite color on the car, but it doesn’t change, can someone help me?
public class Delivery : MonoBehaviour
{
public bool hasPackage;
[SerializeField] float DestroyDelay = 0.5f;
[SerializeField] Color32 hasPackageColor = new Color32(1 , 1, 1, 1);
[SerializeField] Color32 noPackageColor = new Color32(1 , 1, 1, 1);
SpriteRenderer spriteRenderer;
private void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("aouch");
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Package" && !hasPackage){
Debug.Log("package picked");
hasPackage = true;
spriteRenderer.color = hasPackageColor;
Destroy(other.gameObject, DestroyDelay);
}
if (hasPackage == true){
switch(other.tag){
case "bCustomer":
Debug.Log("Delivered to Blue");
hasPackage = false;
break;
case "rCustomer":
Debug.Log("Delivered to Red");
hasPackage = false;
break;
case "oCustomer":
Debug.Log("Delivered to Orange");
hasPackage = false;
break;
}
spriteRenderer.color = noPackageColor;
}
}
}