Advertisement
SizilStank

Untitled

Oct 16th, 2022
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | Gaming | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. using UnityEditor;
  5. using UnityEditor.Animations;
  6.  
  7. public class CharacterSelection : MonoBehaviour
  8. {
  9.  
  10.  
  11.     public Animator animator;
  12.     public List<AnimatorController> skins = new List<AnimatorController>();
  13.  
  14.     public int selectedAnimator;
  15.  
  16.  
  17.  
  18.     private void Start()
  19.     {
  20.  
  21.         Animator animator = GetComponent<Animator>();
  22.     }
  23.  
  24.     public void NextCharacter()
  25.     {
  26.         selectedAnimator = selectedAnimator + 1;
  27.         if (selectedAnimator == skins.Count)
  28.         {
  29.             selectedAnimator = 0;
  30.         }
  31.         animator.runtimeAnimatorController = skins[selectedAnimator];
  32.     }
  33.  
  34.     public void PreviousCharacter()
  35.     {
  36.  
  37.         selectedAnimator = selectedAnimator - 1;
  38.         if (selectedAnimator < 0)
  39.         {
  40.             selectedAnimator = skins.Count -1;
  41.         }
  42.         animator.runtimeAnimatorController = skins[selectedAnimator];
  43.     }
  44.  
  45.     public void StartGame()
  46.     {
  47.        
  48.         PlayerPrefs.SetInt("selectedCharacter", selectedAnimator);
  49.         SceneManager.LoadScene(1, LoadSceneMode.Single);
  50.     }
  51.  
  52.     public void ClearPlayerSelection()
  53.     {
  54.         PlayerPrefs.DeleteKey("selectedCharacter");
  55.     }
  56. }
  57.  
Tags: unity2d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement