my sprite is not changing can’t figure out what the problem is. Even assigned it to maxsprite.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Block : MonoBehaviour
{
//config param
[SerializeField] AudioClip destroySound;
[SerializeField] GameObject blocksparlesVFX;
[SerializeField] int Maxhit;
[SerializeField] Sprite[] hitSprites;
//Cached reference
Level level;
GameStatus gameStatus;
//state variable
[SerializeField] int timesHit; //Only for debug purposes
private void Start()
{
countbreakableblocks();
gameStatus = FindObjectOfType<GameStatus>();
}
private void countbreakableblocks()
{
level = FindObjectOfType<Level>();
if (tag == "Breakable")
{
level.CountBlocks();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (tag == "Breakable")
{
HandleHit();
}
else
{
ShowNextHitSprite();
}
}
private void ShowNextHitSprite()
{
int spriteIndex = timesHit - 1;
GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
}
private void HandleHit()
{
timesHit++;
if (timesHit >= Maxhit)
{
blockdestroy();
}
}
private void blockdestroy()
{
AudioSource.PlayClipAtPoint(destroySound, Camera.main.transform.position);
level.destroyedblock();
gameStatus.addtoscore();
Destroy(gameObject);
TriggersparklesVFX();
}
private void TriggersparklesVFX()
{
GameObject sparkles = Instantiate(blocksparlesVFX, transform.position,transform.rotation);
Destroy(sparkles, 2f);
}
}