Beispiel #1
0
 private void ExtendSnakeRecursive(int count)
 {
     if (bodyParts.Count > 1)
     {
         SnakeMiddleBody bodyPart = Instantiate <SnakeMiddleBody> (middleBodyPrefab, transform);
         bodyPart.Init(this);
         bodyPart.transform.position = bodyParts[bodyParts.Count - 1].transform.position;
         bodyPart.positionX          = bodyParts[bodyParts.Count - 1].positionX;
         bodyPart.positionY          = bodyParts[bodyParts.Count - 1].positionY;
         bodyParts.Insert(bodyParts.Count - 1, bodyPart);
         TiledGameMap.Instance.AddOccupantClean(bodyPart.positionX, bodyPart.positionY, bodyPart);
         count--;
         if (count > 0)
         {
             ExtendSnakeRecursive(count);
         }
     }
     // add tail of not
     if (bodyParts.Count == 1)
     {
         SnakeTail tail = Instantiate <SnakeTail> (tailPrefab, transform);
         tail.Init(this);
         tail.transform.position = bodyParts[0].transform.position;
         tail.positionX          = bodyParts[0].positionX;
         tail.positionY          = bodyParts[0].positionY;
         bodyParts.Add(tail);
         TiledGameMap.Instance.AddOccupantClean(tail.positionX, tail.positionY, tail);
         count--;
         if (count > 0)
         {
             ExtendSnakeRecursive(count);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// This method is repeated every few seconds and spawns a new snake tail from the object pool.
 /// </summary>
 private void SpawnCollider()
 {
     newSnakeTail = ObjectPool.sharedInstance.GetPooledObject();
     newSnakeTail.transform.position = transform.position;
     newSnakeTail.transform.rotation = transform.rotation;
     newSnakeTail.gameObject.SetActive(true);
     newSnakeTail.Init(thinPowerupEnabled, invincible);
     snakeTailList.Add(newSnakeTail);
 }