-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectableCharacter.cs
More file actions
32 lines (28 loc) · 943 Bytes
/
SelectableCharacter.cs
File metadata and controls
32 lines (28 loc) · 943 Bytes
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
// small helper script that is added to character selection previews at runtime
using UnityEngine;
using Mirror;
namespace uMMORPG
{
[RequireComponent(typeof(PlayerIndicator))]
[DisallowMultipleComponent]
public class SelectableCharacter : MonoBehaviour
{
// index will be set by networkmanager when creating this script
public int index = -1;
void OnMouseDown()
{
// set selection index
((NetworkManagerMMO)NetworkManager.singleton).selection = index;
// show selection indicator for better feedback
GetComponent<PlayerIndicator>().SetViaParent(transform);
}
void Update()
{
// remove indicator if not selected anymore
if (((NetworkManagerMMO)NetworkManager.singleton).selection != index)
{
GetComponent<PlayerIndicator>().Clear();
}
}
}
}