void Update() { 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>();//得到点击的mapCube if (selectedTurretData != null && mapCube.turretGo == null) { //可以创建 if (money >= selectedTurretData.cost) { ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData.turretPrefab); } else { //TODO 提示钱不够 moneyAnimator.SetTrigger("flicker"); } } else if (mapCube.turretGo != null) { //TODO 升级处理 } } } } }
private void Update(){ //鼠标被按下 if (Input.GetMouseButtonDown(0)) { //UI没有被选中 if (EventSystem.current.IsPointerOverGameObject() == false) { //MapCube上没有建过炮塔 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//Camera.main tag上标记MainCamera即可 RaycastHit hit; bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube")); if (isCollider) { MapCube mapCube = hit.collider.GetComponent<MapCube>(); //得到点击的mapCube if (mapCube.turretGo == null) { //建造 if (money >= selectedTurretData.cost) { mapCube.BuildTurret(selectedTurretData.turretPrefab); ChangeMoney(-selectedTurretData.cost); } else { //提示钱不够 moneyAnimator.SetTrigger("Flicker"); } } else { //升级 if (money >= selectedTurretData.costUpgraded) { ChangeMoney(-selectedTurretData.costUpgraded); } else { //提示钱不够 } } } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { 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.gameObject.GetComponent <MapCube>(); if (mapCube != null) { if (selectedTurretData != null && mapCube.turrentGo == null) { if (_money >= selectedTurretData.cost) { ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData.turretPrefab); } } else if (mapCube.turrentGo != null) { } } } } } }
void Update() { time += Time.deltaTime; if (time > 1.0) { ChangeMoney(1); time = 0f; } 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; } } } } }
void Update() { moneyText.text = "$" + money; if (getmoney != 0) { ChangeMoney(getmoney); getmoney = 0; } 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")); //Debug.DrawRay(ray,Vector3.up,Color.red); if (isCollider) { MapCube mapCube = hit.collider.GetComponent <MapCube>(); if (mapCube.turretGo == null && selectedTurretData != null) { //可以创建 if (money > selectedTurretData.cost) { ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData); } else { moneyAnimator.SetTrigger("Flick"); //todo 提示钱不够 } } else if (mapCube.turretGo != null) { ShowUpgradedUI(mapCube.transform.position, mapCube.isUpgraded); //if (mapCube.isUpgraded) //{ //ShowUpgradedUI(mapCube.transform.position, true); //} //else //{ // ShowUpgradedUI(mapCube.transform.position, false); //} if (mapCube.turretGo == selectedMapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine(HideUpgradeUI()); } selectedMapCube = mapCube; //todo 升级处理 } } } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { //鼠标坐标不在UI上 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("Map"))) { //获取鼠标点击到的方块 GameObject cube = hit.collider.gameObject; MapCube mapCube = cube.GetComponent <MapCube>(); if (mapCube.turret == null) { //建造炮塔 if (selectedTurret != null) { if (money >= selectedTurret.cost) { ChangeMoney(-selectedTurret.cost); mapCube.BuildTurret(selectedTurret); } else { //金额不足 moneyAnim.SetTrigger("Flicker"); } } } else { //升级炮塔 if (readyUpgradeMapCube != mapCube) { //未选中该炮塔 ShowUpgradeUI(new Vector3(mapCube.transform.position.x, mapCube.transform.position.y + 6, mapCube.transform.position.z + 4), (mapCube.isLevelTop || money < mapCube.turretData.upgradedCost)); readyUpgradeMapCube = mapCube; } else { HideUpgradeUI(); } } } } } if (readyUpgradeMapCube != null) { upgradeBtn.interactable = money >= readyUpgradeMapCube.turretData.upgradedCost && !readyUpgradeMapCube.isLevelTop; } }
private void Update() { if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject() == false)//检测鼠标是否按在UI上 { //炮台的建造 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));//距离1000,获取碰撞的层 if (isCollider) { MapCube mapcube = hit.collider.GetComponent <MapCube>();//得到点击的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) { //升级创建 /*1.方法1 * if(mapcube.isUpgraded) * { * ShowUpgradeUI(mapcube.transform.position,true); * } * else * { * ShowUpgradeUI(mapcube.transform.position, false); * }*/ //2.方法2 if (mapcube == selectedMapCube && upgradeCanvas.activeInHierarchy)//点击同一个炮台 { StartCoroutine(HideUpgradeUI()); } else { ShowUpgradeUI(mapcube.transform.position, mapcube.isUpgraded); } selectedMapCube = mapcube; } } } } }
void Update() { // 鼠标左键按下 if (Input.GetMouseButtonDown(0)) { // 鼠标是否点击到UI上 - 如果是手机上,则需要判断触摸 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) { // 获取到点击的Cube MapCube mapCube = hit.collider.gameObject.GetComponent <MapCube>(); // 已经选择了一个默认的炮塔类型,并且点击的位置的炮塔还没有创建 if (selectedTurretData != null && mapCube.turretGo == null) { // 如果点击的cube下没有炮塔,则可以创建 if (money >= selectedTurretData.cost) { // 金钱数量变化 ChangeMoney(-selectedTurretData.cost); // 创建炮塔 mapCube.BuildTurret(selectedTurretData); } else { // TODO钱不够,给一个提示 moneyAnimator.SetTrigger("Flicker"); } } else if (mapCube.turretGo != null) { if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy) { // 选择的是同一个炮塔,并且炮塔上已经显示了升级UI StartCoroutine(HideUpgradeUI()); } else { // 已经有了炮塔,传递炮塔位置和是否已经升级 ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } // 记录当前选择的炮塔 selectedMapCube = mapCube; } } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject() == false) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hitinfo, 1000f, LayerMask.GetMask("MapCube"))) { currentMap = hitinfo.collider.gameObject.GetComponent <MapCube>(); if (SelectedTurretData != null && currentMap.TurretOn == null) { //create turret if (DataManager.money >= SelectedTurretData.Cost) { MoneyChange(-SelectedTurretData.Cost); currentMap.BuildTurret(SelectedTurretData); } else { MoneyAnimator.SetTrigger("Flicker"); } } else if (currentMap.TurretOn != null) { //upgrade turret if (SelectedTurret == currentMap.TurretOn && isUpgradeUIHide == false) { HideUpgradeUI(); } else { if (currentMap.isUpgraded == false) { UpgradeCost.text = "-" + currentMap.turretData.UpgradeCost + "¥"; DestroyValue.text = "+" + currentMap.turretData.Value + "¥"; ShowUpgradeUI(currentMap.transform.position, currentMap.isUpgraded); } else { UpgradeCost.text = null; DestroyValue.text = "+" + currentMap.turretData.UpgradeValue + "¥"; ShowUpgradeUI(currentMap.transform.position + offset, currentMap.isUpgraded); } } SelectedTurret = currentMap.TurretOn; } } } } }
void Update() { //当点击鼠标左键时 if (Input.GetMouseButtonDown(0)) { //当点击的不是ui时 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 //GameObject mapCube = hit.collider.gameObject; MapCube mapcube = hit.collider.GetComponent <MapCube>(); //Debug.Log(mapcube.name); //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 == selectedMapcube && upgradeCanvas.activeInHierarchy) { StartCoroutine(HideUpgradeUI()); //HideUpgradeUI(); } else { ShowUpgradeUI(mapcube.transform.position, mapcube.isUpgraded); } selectedMapcube = mapcube; } } } } }
private void Update() { // 建炮台 if (Input.GetMouseButtonDown(0)) { // 是否点击到了UI,false => 没有点击到UI if (EventSystem.current.IsPointerOverGameObject() == false) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool bIsCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube")); if (bIsCollider) { MapCube mapCube = hit.collider.GetComponent <MapCube>(); // 此mapCube上没有炮台 => 新建炮台 if (mapCube.m_goTurret == null) { // 有钱 if (GameManager.Instance.m_iMoney >= m_SelectedTurret.m_iCost) { // 花钱 GameManager.Instance.ChangeMoney(-m_SelectedTurret.m_iCost); // 组装炮台 mapCube.BuildTurret(m_SelectedTurret); } // 穷人 else { // 钱闪一下,提示你是个穷人 m_animMoneyFlicker.SetTrigger("Flicker"); } } // 此mapCube上有炮台 => 显示升级炮台面板 else { // 点击的是同一个MapCube,隐藏升级面板 if (m_CurMapCube == mapCube && m_goCanvasUpgrade.activeInHierarchy) { StartCoroutine(HideUpgradePanel()); } else { ShowUpgradePanel(mapCube.transform.position, mapCube.m_bIsUpgraded); } // 保存此次点击的炮台 m_CurMapCube = mapCube; } } } } }
void Update() { 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 //GameObject mapcube = hit.collider.gameObject; MapCube mapCube = hit.collider.GetComponent <MapCube>(); if (mapCube.turretGo == null) //mapcube上没有炮塔 { if (money > selectedTurret.cost) { ChangeMoney(-selectedTurret.cost); if (selectedTurret.turretPrefab == null) { return; } mapCube.BuildTurret(selectedTurret); } else { //提示资金不够 moneyAnim.SetTrigger("flicker"); } } else { //TODO 升级炮塔 ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); if (mapCube.turretGo == selectedMapcube && upgradeCanvas.activeInHierarchy) { HideUpgradeUI(); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapcube = mapCube; } } } } }
private void Update() { if (!selectLaserTurret && !selectMissileTurret && !selectStandardTurret) { selectedTurretData = null; } if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { //点击左键 并且没有点击UI 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 (mapCube.turretGo == null) { if (selectedTurretData != null && money < selectedTurretData.cost) { moneyAnimator.SetTrigger("Flicker"); } //可以创建炮台 if (selectedTurretData != null && money >= selectedTurretData.cost) { StartCoroutine("HideUpgradeUI"); ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData); //selectedTurretData = null; } } else { //升级炮台 if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine("HideUpgradeUI"); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapCube = mapCube; } } } } }
void Update() { //如果按下 if (Input.GetMouseButtonDown(0)) { //并且不在ui 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) { //GameObject gameObject = hit.collider.gameObject; MapCube mapCube = hit.collider.GetComponent <MapCube>(); if (selectedTurretData != null && mapCube.turretGo == null) { //可以建造 if (money > selectedTurretData.cost) { ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData); } else { moneyFlicker.SetTrigger("Flicker"); } } else { //升级 if (mapCube.turretGo != null) { if (mapCube == selectedMapCube && upgradeCanvers.activeInHierarchy) { StartCoroutine(HideUpgradeUI()); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraed); } selectedMapCube = mapCube; } } } } } }
void CreateTurret(MapCube mapCube) { if (selectTurret == null) { return; } if (money < selectTurret.cost) { // 钱不够 moneyAnimator.SetTrigger("Flicker"); return; } ChangeMoney(-selectTurret.cost); mapCube.BuildTurret(selectTurret); }
private void Update() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) //鼠标没有在UI上 { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitImfo; bool isCollide = Physics.Raycast(ray, out hitImfo, 1000, LayerMask.GetMask("MapCube")); if (isCollide) { // GameObject mapCube = hitImfo.collider.gameObject; //得到鼠标指向的MapCube MapCube mapCube = hitImfo.collider.GetComponent <MapCube>(); if (selectedData != null && mapCube.turretOn == null) { //可以创建Turret if (money >= selectedData.cost) { UpdateMoney(-selectedData.cost); mapCube.BuildTurret(selectedData); } else { //提示钱不够 moneyAnimator.SetTrigger("Flick"); } } else if (mapCube.turretOn != null) { //升级 if (this.mapCube == mapCube && upgradeCanvas.activeInHierarchy) { HideUpgradeCanvas(); } else { ShowUpgradeCanvas(mapCube.transform.position, mapCube.isUpgraded); } this.mapCube = mapCube; } } } } }
private void Update() { 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>(); //得到点击的MapCube if (mapCube.turretGO == null) //判断MapCube上没有炮台 { if (selectedTurret != null) //selectedTurret不为空才能进行建造炮台 { //可以创建 if (money >= selectedTurret.cost)//判断钱够不够 { ChangeMoney(selectedTurret.cost); mapCube.BuildTurret(selectedTurret); } else { //TODO钱不够 moneyText.gameObject.GetComponent <Animator>().SetTrigger("Flicker"); } } } else//若mapCube上有炮台了,再次点击就会提示升级 { //TODO升级处理 if (selectedMapCube == mapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine("HideUpgradeUI"); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapCube = mapCube; } } } } }
void Update() { //对鼠标按下的cube进行检测,是否能进行创建 if (Input.GetMouseButtonDown(0)) { //检测指针是否在UI上 if (EventSystem.current.IsPointerOverGameObject() == false) { //满足以上两个条件才能创建塔 //先进行mapCube检测 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>();//获取mapCube GameObject if (selectedTurretData != null && mapCube.turretGo == null) { //可以创建 if (money >= selectedTurretData.cost) { changeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData);//在MapCube中创建 } else { //No Enough Money moneyAnimator.SetTrigger("Flicker"); } } else if (mapCube.turretGo != null) { if (mapCube == selectedMapcube && UpgradeCanvas.activeInHierarchy) { StartCoroutine(HideUpgradeUI());//启动协程 } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgrade); //升级处理 } selectedMapcube = mapCube; //更新当前选择的炮台 } } } } }
void Update() { 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>();//得到点击的mapcube if (selectTurretData != null && mapCube.turretGo == null) { //可以创建 if (money > selectTurretData.cost) { ChangeMoney(-selectTurretData.cost); mapCube.BuildTurret(selectTurretData); } else { //钱不够 moneyAnimator.SetTrigger("flicker"); } } else if (mapCube.turretGo != null) { //升级 if (mapCube == selectedMapcube && upgradeCanvas.activeInHierarchy) { //StartCoroutine(hideUpgradeUI()); hideUpgradeUI(); } else { showUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapcube = mapCube; } } } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject() && _selectedTurretData._turretPrefab != null) { //建造炮台 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool isCollider = Physics.Raycast(ray, out hit, 500, LayerMask.GetMask("MapCube")); if (isCollider) { MapCube mapCube = hit.collider.gameObject.GetComponent <MapCube>();; if (mapCube.turretGo == null) { //可以创建 if (Money > _selectedTurretData._cost) { //开始建造 mapCube.BuildTurret(_selectedTurretData); UpdateMoney(-_selectedTurretData._cost); } else { //提示钱不够 moneyAnim.SetTrigger("flicter"); } } else { //不可以创建 if (mapCube == _selectedMapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine(HideUpgradeUI()); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.IsUpgrade); } _selectedMapCube = mapCube; } } } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { //当点击的不是UI时,进行UI炮台的建设 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 (selectTurretData != null && mapCube.turretGo == null) { //可以创建 if (money > selectTurretData.cost) { mapCube.BuildTurret(selectTurretData); //HideUpgradeUI(); ChangeMoney(-selectTurretData.cost); } else { //TODO 提示钱不够 moneyAnimator.SetTrigger("Flicker"); } } else if (mapCube.turretGo != null) { // 升级处理 if (mapCube == selectMapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine(HideUpgradeUI()); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectMapCube = mapCube; } } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { //检测是否点击到了UI if (EventSystem.current.IsPointerOverGameObject() == false) { //检测是否点击到了mapCube 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>(); // 点击的mapCube if (mapCube.turret == null && selectedTurret != null) { //创建炮台 if (money >= selectedTurret.cost) { ChangeMoney(-selectedTurret.cost); mapCube.BuildTurret(selectedTurret); } else { moneyAnimator.SetTrigger("Flick"); } } else if (mapCube.turret != null) { //显示升级UI if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine(ButtonHide()); } else { ButtonShow(mapCube.transform.position, mapCube.isUpgraded); } selectedMapCube = mapCube; } } } } }
void Update() { if (Input.GetMouseButtonDown(0)) // 监测鼠标左键点击 { if (!EventSystem.current.IsPointerOverGameObject()) // 鼠标没有点击 UI 图标 { // 有鼠标所在位置发射射线 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 == selectedMapCube && upgradeCanvas.activeInHierarchy) { StartCoroutine(HideUpgradeUI()); // 隐藏面板 } else // 否则显示面部 { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapCube = mapCube; } } } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool ishit = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube")); if (ishit) { MapCube mapCube = hit.collider.GetComponent <MapCube>(); if (mapCube.turrentGo == null && selectTurretData != null) { if (money >= selectTurretData.cost) { ChangeMoney(-selectTurretData.cost); mapCube.BuildTurret(selectTurretData); } else { moneyAnim.SetTrigger("Filck"); } } else if (mapCube.turrentGo != null) { if (mapCube == selectMapCube && upgradeCanvas.activeInHierarchy) { HideUpgradeUI(); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgrade, mapCube.turretData.costUpgrade); } selectMapCube = mapCube; } } } } }
void Update() { 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 (gameManager.money >= selectedTurretData.level1.cost) { SpendMoneyEvent(this, new SpendMoneyEventArgs(selectedTurretData.level1.cost)); mapCube.BuildTurret(selectedTurretData); } else { moneyAnimator.SetTrigger("Flicker"); } } else if (mapCube.turretGo != null) { if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy) { upgradeCanvas.SetActive(false); } else { ShowUpgradeUI(mapCube.transform.position, mapCube.currentLevel); } selectedMapCube = mapCube; } } } } }
void Update() { GetMoneyFromEnemy(); 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 (mapCube.turretGo == null && selectedTurret != null) { //可以创建 if (totalMoney >= selectedTurret.cost) { ChangeMoney(-selectedTurret.cost); mapCube.BuildTurret(selectedTurret); } else { //提示钱不够 moneyAnimator.SetTrigger("Flicker"); } } else if (mapCube.turretGo != null) { //升级处理 ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgrade); } selectedMapCube = mapCube; } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { //利用UI控件的EventSystem组件判断鼠标点击是否发生在UI控件上 if (EventSystem.current.IsPointerOverGameObject() == false) { //建造炮台 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //通过物理射线Ray对象来判断1000单位距离之内与"MapCube"层是否发生碰撞,并将碰撞信息传入hit对象中 bool isCoilder = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube")); //如果发生碰撞,获取到点击到的MapCube物体 if (isCoilder) { MapCube mapCube = hit.collider.GetComponent <MapCube>(); //如果该MapCube上没有炮台,则可以建造 if (mapCube.turret == null) { //如果剩余金额足够 if (totalMoney >= selectedTurretData.coast) { mapCube.BuildTurret(selectedTurretData.turretPrefab); changeMoney(-selectedTurretData.coast); } else //余额不足显示动画 { moneyAnimator.SetTrigger("Flick"); } } else { } } } } }
//-------paremeter 0 = plus, 1 = minus, 2 = mult, 3 = euqual public void OnSubmitFirstAnswer() { if (isEqualOpen) { if (trueCompare == 1) { //answer correct, can build turret mapCube.BuildTurret(pubSignSymbol); HideBuildOperationUI(); isEqualOpen = false; } else { //answer wrong, reset all numbers BuildPanelAnimator.Play("BuildingWrongAnswerAnnim", -1, 0); firstAnswer.GetComponentInParent <Animator>().Play("AnswerShake", -1, 0); TDSoundManager.instance.playWrongSound(); //Invoke("showQuestionUI",0.9f); showQuestionUI(pubSignSymbol); } } else { if (int.Parse(firstAnswer.text) == trueAnswer) { //answer correct, can build turret mapCube.BuildTurret(pubSignSymbol); HideBuildOperationUI(); } else { //answer wrong, reset all numbers BuildPanelAnimator.Play("BuildingWrongAnswerAnnim", -1, 0); firstAnswer.GetComponentInParent <Animator>().Play("AnswerShake", -1, 0); TDSoundManager.instance.playWrongSound(); //Invoke("showQuestionUI",0.9f); showQuestionUI(pubSignSymbol); } } }
void Update() { if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject()) { return; } //炮台的建造 //1。必须点在mapCube上 //2.该mapCube必须是空的 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube")); if (!isCollider) { return; } // Debug.Log("检测到射线碰撞"); //得到点击的Cube MapCube mapCube = hit.collider.GetComponent <MapCube>(); if (null != mapCube.turretGo) { if (selectedMapCube == mapCube) { if (UpgradeCanvas.activeInHierarchy) { //hideUpgradeUI(); StartCoroutine(hideUpgradeUI()); } else { // 显示升级菜单 ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } } else { ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapCube = mapCube; return; } if (null == selectedTurretData) { return; } if (money < selectedTurretData.cost) { //给出钱不够的提示 moneyAnimator.SetTrigger("flicker"); return; } // 创建新的 ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData); //mapCube.GetComponent<MeshRenderer>().material.color = new Color(255, 0, 0); } }
void Update() { 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>(); Debug.Log(mapCube.name + " " + mapCube.isFlipped); // 扫雷,显示数字 if (!mapCube.isFlipped) // 没翻,还要判定有没有插旗 { if (myFH.flagModel) //如果有按flag 按钮进入插旗模式 { //插旗,生成旗帜模型, mapCube.buildFlag(mapCube); mapCube.isFlipped = true; Debug.Log("Set Flag"); } else if (money >= flipcost) { ChangeMoney(-flipcost); mapCube.BuildNumber(mapCube); if (mapCube.isMine) { ChangeMine(-1); } } else { MineAudio.Play(); //提示钱不够 moneyAnimator.SetTrigger("Flicker"); } } else if (mapCube.isFlipped && mapCube.hasFlag && selectedTurretData != null && mapCube.turretGo == null)//翻,有旗 { //判定 //Cube确实是Mine if (mapCube.name.Equals("MapCubeM")) { //Buildbonus if (money >= selectedTurretData.cost) { ChangeMine(-1); ChangeMoney(-selectedTurretData.cost); mapCube.BonusTurret(selectedTurretData); } else { MineAudio.Play(); //提示钱不够 moneyAnimator.SetTrigger("Flicker"); } } else { //变叉 if (money >= selectedTurretData.cost) { ChangeMoney(-selectedTurretData.cost); mapCube.BuildWrong(mapCube); } else { MineAudio.Play(); //提示钱不够 moneyAnimator.SetTrigger("Flicker"); } } } else if (mapCube.isFlipped && !mapCube.isMine && !mapCube.hasFlag && selectedTurretData != null && mapCube.turretGo == null)//翻,无旗 { if (money >= selectedTurretData.cost) { ChangeMoney(-selectedTurretData.cost); mapCube.BuildTurret(selectedTurretData); } else { MineAudio.Play(); //提示钱不够 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 { dropMoneyText.text = "+$" + (int)((float)mapCube.turretData.cost * 0.8); ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded); } selectedMapCube = mapCube; } } } } }