51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
[ExecuteAlways]
|
|
public class Node : MonoBehaviour
|
|
{
|
|
[Range(-1, 1)]
|
|
[SerializeField]
|
|
private int Owner = -1;
|
|
public Material materialOwnerSelf, materialOwnerOther, materialOwnerNone;
|
|
|
|
|
|
void Awake()
|
|
{
|
|
UpdateColor();
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
UpdateTransform();
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
UpdateColor();
|
|
UpdateTransform();
|
|
}
|
|
|
|
public void UpdateTransform()
|
|
{
|
|
transform.localPosition = transform.localPosition.normalized * 20f;
|
|
transform.forward = transform.position;
|
|
}
|
|
|
|
public void UpdateColor()
|
|
{
|
|
switch (Owner)
|
|
{
|
|
case -1: transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = materialOwnerNone; break;
|
|
case 0: transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = materialOwnerSelf; break;
|
|
case 1: transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = materialOwnerOther; break;
|
|
}
|
|
}
|
|
|
|
}
|