Guest User

Untitled

a guest
Apr 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. Dictionary <int,int> animDict
  2.  
  3. public void AddAnimation(int[] numbers, int anim)
  4. {
  5.     if (numbers.Length != 9) return;
  6.     animDict[Index(numbers)] = anim;
  7. }
  8.  
  9. public void Awake()
  10. {
  11.     AddAnimation({ 0,0,1, 1,0,0, 0,0,0 },43);
  12.     AddAnimation({ 0,1,1, 1,0,0, 0,0,0 },42);
  13.    
  14.  
  15. }
  16.  
  17. private int Index(int[] numbers)
  18. {
  19.     int result = 0;
  20.     foreach(int number in numbers)
  21.     {
  22.         result *= 2;
  23.         result += number;
  24.     }
  25.     return result;
  26. }
  27.  
  28. void SpawnBorder( int[] firstCheck, Vector3[] firstCheckPostion )
  29. {
  30.     int index = Index(firstCheck);
  31.  
  32.     int anim = 0;
  33.     if (animDict.TryGetValue(index, out anim)
  34.     {
  35.         GameObject spawnBorder = Instantiate(SoilBorders,LevelCreator.gridPositionArray[tempPlayerX, tempPlayerY],Quaternion.identity) as GameObject;
  36.      
  37.         spawnBorder.transform.position = new Vector3(spawnBorder.transform.position.x,spawnBorder.transform.position.y,0.07f);
  38.         PackedSprite borderType = spawnBorder.GetComponent<PackedSprite>();
  39.         borderType.PlayAnim(anim);
  40.     }
  41.     else
  42.     {
  43.         // Not found error
  44.     }
  45. }
Add Comment
Please, Sign In to add comment