5Y5T3M/Assets/Scripts/Node.cs

52 lines
1.2 KiB
C#
Raw Normal View History

2025-09-15 23:01:07 +02:00
using UnityEngine;
2025-09-16 00:08:50 +02:00
[ExecuteAlways]
2025-09-15 23:01:07 +02:00
public class Node : MonoBehaviour
{
2025-09-16 14:20:19 +02:00
[Range(-1, 1)]
[SerializeField]
2025-09-17 10:12:15 +02:00
public int Owner = -1;
public Material materialOwnerSelf, materialOwnerOther, materialOwnerNone;
void Awake()
{
UpdateColor();
}
2025-09-16 14:20:19 +02:00
2025-09-15 23:01:07 +02:00
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
2025-09-15 23:01:07 +02:00
}
// 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()
{
2025-09-16 14:20:19 +02:00
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;
}
}
2025-09-16 17:40:34 +02:00
2025-09-15 23:01:07 +02:00
}