using UnityEngine;
using System.Collections;
using TNet;
[RequireComponent
(typeof(CharacterController
))] [RequireComponent
(typeof(CharacterFirstPersonMouseLook
))] [RequireComponent
(typeof(CharacterMotor
))] public class Character : TNBehaviour
{
public int hp = 100;
public int updatesPerSecond = 3;
public bool localPlayer = false;
private GameLocal gamelocal;
void Awake()
{
// Only start the coroutine if we wanted to run periodic updates
if (updatesPerSecond > 0 && TNManager.isInChannel && tno.isMine)
{
StartCoroutine(PeriodicSync());
}
}
void Start ()
{
//gamelocal = GameObject.Find("GameLocal").GetComponent<GameLocal>();
if (tno.isMine)
{
localPlayer = true;
}
else
{
//GetComponent<CharacterFirstPersonMouseLook>().enabled = false;
GetComponentInChildren<Camera>().enabled = false;
GetComponentInChildren<AudioListener>().enabled = false;
GetComponent<MeshRenderer>().enabled = true;
}
}
void Update ()
{
}
IEnumerator PeriodicSync()
{
for (; ; )
{
tno.SendQuickly("SyncPosRot", Target.Others, transform.position, transform.rotation);
if (updatesPerSecond > 0)
{
yield return new WaitForSeconds
(1f
/ updatesPerSecond
); }
else yield return new WaitForSeconds
(0
.01f
);
}
}
[RFC]
void SyncPosRot(Vector3 _pos, Quaternion _rot)
{
transform.position = _pos;
transform.rotation = _rot;
}
}