Astar_demo/Assets/cellData.cs
2023-11-28 11:29:52 +05:30

64 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class cellData : MonoBehaviour
{
public TextMesh gCostTxt;
public TextMesh hCostTxt;
public TextMesh fCostTxt;
public float fCost,gCost,hCost;
public List<cellData> neighbours = new List<cellData>();
public int y;
public int x;
private bool _isObstacle = false;
public bool isObstacle => _isObstacle;
private bool _isClose = false;
public bool isClose => _isClose;
public bool isInPath;
public cellData parent;
public void setCellCost(float g, float h, float f){
gCostTxt.text =g.ToString("n2");
hCostTxt.text = h.ToString("n2");
fCostTxt.text = f.ToString("n2");
fCost= f;
gCost = g;
hCost = h;
}
public void setClose(bool value){
_isClose = value;
if(value){
GetComponent<SpriteRenderer>().color = Color.red;
}else{
setObstacle();
}
}
public void resetCost(){
setCellCost(0,0,0);
setClose(false);
}
public void setObstacle(bool value){
_isObstacle = value;
if(value){
GetComponent<SpriteRenderer>().color = Color.black;
}else{
GetComponent<SpriteRenderer>().color = Color.white;
}
}
public void setObstacle(){
if(_isObstacle){
GetComponent<SpriteRenderer>().color = Color.black;
}else{
GetComponent<SpriteRenderer>().color = Color.white;
}
}
}