コード例 #1
0
        // *************************** score
        public int CheckDebrisForScore(Debris.Kind targetDebrisKind)
        {
            int matchCount = 0;

            foreach (Transform trans in debrisTrunk)
            {
                if (trans.gameObject.activeSelf == false)
                {
                    break;
                }

                if (trans.gameObject.CompareTag(GameTag.TAG_PLAYER_KID))
                {
                    Debris d = trans.gameObject.GetComponent <Debris>();
                    if (d)
                    {
                        if (d.kind == targetDebrisKind)
                        {
                            matchCount++;
                        }
                    }
                }
            }

            return(matchCount);
        }
コード例 #2
0
        void Start()
        {
            // get refs
            player           = GameObject.FindWithTag(GameTag.TAG_PLAYER).transform;
            playerController = player.GetComponent <PlayerController>();
            audioSource      = GetComponent <AudioSource>();

            // generate debris
            // ----------------------------------------------------------
            // ... ensure pos val
            if (debrisCount <= 0)
            {
                debrisCount = 1;
            }

            int maxTargetDebrisCount = debrisCount / targetDebrisReductionFactor;

            if (maxTargetDebrisCount < 1)
            {
                maxTargetDebrisCount = 1;
            }
            targetDebrisCount = Random.Range(1, maxTargetDebrisCount);
            _targetDebrisKind = GetRandomDebrisKind();
            // ----------------------------------------------------------

            // begin fun!
            StartCoroutine(GameLoop());
        }
コード例 #3
0
		public void Init(int itemCount = 10, 
							int minSpecificPrefabCount = -1, 
							Debris.Kind specificPrefabDebrisKind = Debris.Kind.Blue)
		{
			pooledObjects = new List<GameObject>();

			int rNum = -1;
			if(minSpecificPrefabCount > 0 && minSpecificPrefabCount <= itemCount)
			{
				rNum = minSpecificPrefabCount;
			}

			for(int i = 0; i < itemCount; i++)
			{
				GameObject obj = null;
				if(rNum > 0 && i < rNum)
				{
					obj = (GameObject)Instantiate(GetPrefabByDebrisKind(specificPrefabDebrisKind));
				}
				else
				{
					obj = (GameObject)Instantiate(GetRandomPrefab());
				}
				
				obj.SetActive(false);
				pooledObjects.Add(obj);
			}

			_poolCount = itemCount;
		}
コード例 #4
0
        private void CreateDebris(int totalCount,
                                  int specialDebrisCount        = -1,
                                  Debris.Kind specialDebrisKind = Debris.Kind.Blue,
                                  string parentName             = "debris")
        {
            // init pool
            ObjectPooler.current.Init(totalCount, specialDebrisCount, specialDebrisKind);

            // create parent
            GameObject newParent = new GameObject(parentName);

            newParent.transform.parent = gameObject.transform;

            for (int i = 0; i < totalCount; i++)
            {
                GameObject obj = ObjectPooler.current.GetPooledObject();

                obj.transform.position = new Vector3(Random.Range(-posScale, posScale),
                                                     debrisHeight,
                                                     Random.Range(-posScale, posScale));

                obj.transform.parent = newParent.transform;

                obj.SetActive(true);
            }
        }
コード例 #5
0
		private GameObject GetPrefabByDebrisKind(Debris.Kind kind)
		{
			foreach(GameObject go in prefabs)
			{
				Debris debris = go.GetComponent<Debris>();
				if(debris != null)
				{
					if(debris.kind == kind)
					{
						return go;
					}				
				}
			}

			return null;
		}