-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectMenuController.cs
More file actions
41 lines (32 loc) · 1.25 KB
/
SelectMenuController.cs
File metadata and controls
41 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelectMenuController : MonoBehaviour {
public MainMenuPlayerController mainPlayer;
public RuntimeAnimatorController[] anims;
public MainMenuPlayerController[] avatars;
int currIdx;
void Start() {
string animName = PlayerPrefs.GetString("PlayerAnim", "BlueAstroAnim");
// Turn off all jumps excepted selected
for (int i = 0; i < avatars.Length; i++) {
MainMenuPlayerController avatar = avatars[i].GetComponent<MainMenuPlayerController>();
avatar.SetInitHeight();
if (anims[i].name == animName) currIdx = i;
else avatar.SetJump(false);
}
}
public void SelectCharacter(int index) {
if (currIdx == index) return;
// Turn off jump for previous selection
avatars[currIdx].GetComponent<MainMenuPlayerController>().SetJump(false);
// Toggle jump for new selection
avatars[index].GetComponent<MainMenuPlayerController>().SetJump(true);
currIdx = index;
}
public void ConfirmCharacter() {
mainPlayer.ChangeCharacter(anims[currIdx]);
// Set in player prefs to be accessed in game scene
PlayerPrefs.SetString("PlayerAnim", anims[currIdx].name);
}
}