学习目标:熟悉塔防游戏核心战斗
游戏画面
项目结构目录
核心代码:
if ( Input.GetMouseButtonDown(0))
{
if (EventSystem.current.IsPointerOverGameObject()==false)
{
//开发炮台的建造
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray,out hit, 1000, LayerMask.GetMask("MapCube"));
if (isCollider)
{
MapCube mapCube = hit.collider.GetComponent<MapCube>();
if (selectedTurretData != null && mapCube.turretGo == null)
{
//可以创建
if (money > selectedTurretData.cost)
{
ChangeMoney(-selectedTurretData.cost);
mapCube.BuildTurret(selectedTurretData);
}
else
{
//提示钱不够
moneyAnimator.SetTrigger("Flicker");
}
}
else if (mapCube.turretGo != null)
{
// 升级处理
//if (mapCube.isUpgraded)
//{
// ShowUpgradeUI(mapCube.transform.position, true);
//}
//else
//{
// ShowUpgradeUI(mapCube.transform.position, false);
//}
if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy)
{
StartCoroutine(HideUpgradeUI());
}
else
{
ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded);
}
selectedMapCube = mapCube;
}
}
}
}
}