0
Привет им пытаются преобразовать код, который работает на 3D-проекта, чтобы получить GameObject, который я нажимаю на моей мыши работать на 2D, так как им в настоящее время делает проект 2DПреобразование Raycast из 3D в 2D
public class SetTower : MonoBehaviour {
public int selected;
public GameObject[] towers;
public float[] prices;
public GameObject tile;
private Money moneyScript;
// Use this for initialization
void Start()
{
moneyScript = GameObject.Find("GameLogic").GetComponent<Money>();
}
// Update is called once per frame
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 20))
{
if(hit.transform.tag == "Tile")
{
tile = hit.transform.gameObject;
}
else
{
tile = null;
}
if (Input.GetMouseButtonDown(0) && tile != null)
{
TileTaken tileScript = tile.GetComponent<TileTaken>();
if(!tileScript.isTaken && moneyScript.money >= prices[selected])
{
moneyScript.money -= prices[selected];
Vector2 pos = new Vector2(tile.transform.position.x, tile.transform.position.y);
tileScript.tower = (GameObject)Instantiate(towers[selected], pos, Quaternion.identity);
tileScript.isTaken = true;
}
}
}
}
}