You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.2 KiB
63 lines
1.2 KiB
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Charge : MonoBehaviour {
|
|
|
|
|
|
//General information
|
|
public int id;
|
|
private int actorNumber;
|
|
public int ActorNumber {
|
|
get => actorNumber;
|
|
set {
|
|
if (value == -1)
|
|
actorNumber = 0;
|
|
else
|
|
actorNumber = value;
|
|
|
|
UpdatePlayerMaterial();
|
|
}
|
|
}
|
|
|
|
|
|
//Gameplay
|
|
public float Speed {
|
|
get;
|
|
set;
|
|
}
|
|
public void UpdateCharge(float tickRate) {
|
|
Vector3 dir = new Vector3(0, Speed, 0) * Time.deltaTime * tickRate;
|
|
transform.Translate(dir);
|
|
}
|
|
public bool HasReached(Circuit receiver) {
|
|
float dist = Vector3.Distance(transform.position, receiver.transform.position);
|
|
float maxDist = chargeRenderer.bounds.extents.magnitude;
|
|
return dist < maxDist;
|
|
}
|
|
|
|
|
|
//Called by Unity
|
|
void Start() {
|
|
|
|
}
|
|
void Update() {
|
|
if (Game.Instance) {
|
|
if (!PhotonNetwork.IsMasterClient && Game.Instance.IsPlaying && !PhotonNetwork.MasterClient.IsInactive)
|
|
UpdateCharge(Game.Instance.tickRate);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//Everything Visual
|
|
private Renderer chargeRenderer;
|
|
private void Awake() {
|
|
chargeRenderer = GetComponent<Renderer>();
|
|
}
|
|
private void UpdatePlayerMaterial() {
|
|
chargeRenderer.material = ColorManager.GetChargeBy(ActorNumber);
|
|
}
|
|
}
|
|
|