當前位置: 首頁>>代碼示例>>C#>>正文


C# UnitTower.GetRange方法代碼示例

本文整理匯總了C#中TDTK.UnitTower.GetRange方法的典型用法代碼示例。如果您正苦於以下問題:C# UnitTower.GetRange方法的具體用法?C# UnitTower.GetRange怎麽用?C# UnitTower.GetRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TDTK.UnitTower的用法示例。


在下文中一共展示了UnitTower.GetRange方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BuildTower

        //called by any external component to build tower, uses buildInfo
        public static string BuildTower(UnitTower tower)
        {
            if (buildInfo == null) return "Select a Build Point First";

              UnitTower sampleTower = GetSampleTower(tower);

              /***/
              // check if there's energy reciving tower
              if (tower.electricityNeeded && !tower.electricityReciever && !tower.electricityFacility)
              {
            LayerMask maskTarget = 1 << LayerManager.LayerTower();

            Collider[] cols = Physics.OverlapSphere(buildInfo.position, 1000 /*GetRange()*/, maskTarget);

            if (cols.Length > 0)
            {
              tower.electicitySources.Clear();
              // find all electric facility
              for (int i = 0; i < cols.Length; i++)
              {
            // if it's not electric reciever skip
            if (!cols[i].gameObject.GetComponent<UnitTower>().electricityReciever)
              continue;

            //float test = cols[i].gameObject.GetComponent<UnitTower>().GetRange();
            //float test2 = Vector3.Distance(cols[i].gameObject.GetComponent<UnitTower>().transform.position, buildInfo.position);

            // if this tower is in range of electricityReciever
            if (Vector3.Distance(cols[i].gameObject.GetComponent<UnitTower>().transform.position, buildInfo.position) <= cols[i].gameObject.GetComponent<UnitTower>().GetRange())
            {
              tower.electicitySources.Add(cols[i].gameObject.GetComponent<UnitTower>());
            }
              }

              if (tower.electicitySources.Count == 0)
              {
            // set electricity source for tower weapon
            return "There is not enough electricity";
              }
            }
            else
              return "There is not enough electricity";
              }
              /***/

              //check if there are sufficient resource
              List<int> cost = sampleTower.GetCost();
              int suffCost = ResourceManager.HasSufficientResource(cost);
              if (suffCost == -1)
              {
            ResourceManager.SpendResource(cost);

            GameObject towerObj = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation);
            UnitTower towerInstance = towerObj.GetComponent<UnitTower>();
            towerInstance.InitTower(instance.towerCount += 1, buildInfo.platform);
            towerInstance.Build();

            // if new electricity reciver is placed search for all towers in it's range and add itself as electricity source
            if (tower.electricityReciever)
            {
              LayerMask maskTarget = 1 << LayerManager.LayerTower();

              Collider[] cols = Physics.OverlapSphere(buildInfo.position, tower.GetRange(), maskTarget);

              if (cols.Length > 0)
              {
            UnitTower tmp_tow;
            for (int i = 0; i < cols.Length; i++)
            {
              tmp_tow = cols[i].gameObject.GetComponent<UnitTower>();

              if (tmp_tow.electricityReciever || tmp_tow.electricityFacility)
                continue;

              tmp_tow.electicitySources.Add(towerInstance);
            }
              }
            }

            //clear the build info and indicator for build manager
            ClearBuildPoint();

            return "";
              }

              return "Insufficient Resource";
        }
開發者ID:toooooooo,項目名稱:BEER,代碼行數:88,代碼來源:BuildManager.cs

示例2: _SelectTower

        public void _SelectTower(UnitTower tower)
        {
            _ClearSelectedTower();

            selectedTower=tower;

            float range=tower.GetRange();

            Transform indicatorT=rangeIndicator;

            if(indicatorT!=null){
                indicatorT.parent=tower.thisT;
                indicatorT.position=tower.thisT.position;
                indicatorT.localScale=new Vector3(2*range, 1, 2*range);

                indicatorT.gameObject.SetActive(true);
            }
        }
開發者ID:Pringlez,項目名稱:Alien-Danger-TD,代碼行數:18,代碼來源:GameControl.cs

示例3: _SelectTower

		public void _SelectTower(UnitTower tower){
			_ClearSelectedTower();
			
			selectedTower=tower;
			
			if(tower.type==_TowerType.Block || tower.type==_TowerType.Resource) return;
			
			float range=tower.GetRange();
			
			Transform indicatorT=!tower.directionalTargeting ? rangeIndicator : rangeIndicatorCone;
			
			if(indicatorT!=null){
				indicatorT.parent=tower.thisT;
				indicatorT.position=tower.thisT.position;
				indicatorT.localScale=new Vector3(2*range, 1, 2*range);
				
				if(tower.directionalTargeting) indicatorT.localRotation=Quaternion.identity*Quaternion.Euler(0, tower.dirScanAngle, 0);
				
				indicatorT.gameObject.SetActive(true);
			}
		}
開發者ID:ahvdesign,項目名稱:Tower-Defense-Q,代碼行數:21,代碼來源:GameControl.cs


注:本文中的TDTK.UnitTower.GetRange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。