65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Cell : MonoBehaviour
|
|
{
|
|
public GameObject deck;
|
|
private GameObject crossSprite;
|
|
private GameObject missSprite;
|
|
private GameObject reefSprite; // ← новый дочерний объект
|
|
|
|
public Material hitMaterial;
|
|
|
|
void Awake()
|
|
{
|
|
crossSprite = transform.Find("Cross").gameObject;
|
|
missSprite = transform.Find("Miss").gameObject;
|
|
reefSprite = transform.Find("Reef")?.gameObject; // null-safe: если нет — просто не использует
|
|
HideAll();
|
|
}
|
|
|
|
public void ShowCross()
|
|
{
|
|
crossSprite.SetActive(true);
|
|
missSprite.SetActive(false);
|
|
}
|
|
|
|
public void ShowMiss()
|
|
{
|
|
crossSprite.SetActive(false);
|
|
missSprite.SetActive(true);
|
|
}
|
|
|
|
/// <summary>Показывает риф/препятствие (Быстрая игра 2).</summary>
|
|
public void ShowReef()
|
|
{
|
|
if (reefSprite != null)
|
|
reefSprite.SetActive(true);
|
|
}
|
|
|
|
public void HideAll()
|
|
{
|
|
crossSprite.SetActive(false);
|
|
missSprite.SetActive(false);
|
|
if (reefSprite != null)
|
|
reefSprite.SetActive(false);
|
|
}
|
|
|
|
public bool hit()
|
|
{
|
|
bool hit = false;
|
|
|
|
if (deck)
|
|
{
|
|
ShowCross();
|
|
var deckScript = deck.GetComponent<Deck>();
|
|
if (deckScript != null && !deckScript.isHit)
|
|
deckScript.ApplyHit();
|
|
return true;
|
|
}
|
|
ShowMiss();
|
|
return hit;
|
|
}
|
|
}
|