Cyber/Assets/Scripts/Controls/PlayerController.cs

42 lines
1.4 KiB
C#
Raw Normal View History

2017-05-08 23:03:02 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Entities;
using Cyber.Console;
2017-05-09 06:15:34 +02:00
using Cyber.Networking.Clientside;
using Cyber.Networking;
using Cyber.Networking.Messages;
2017-05-08 23:03:02 +02:00
namespace Cyber.Controls {
/// <summary>
/// Controls the player character. Shouldn't exist on the server, and only one
/// should exist per client (the character that client is controlling).
/// </summary>
public class PlayerController : MonoBehaviour {
/// <summary>
/// The character this controller should control.
/// </summary>
public Character Character;
private void Update() {
if (!Term.IsVisible()) {
// Handle inputs
Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if (Move.sqrMagnitude != 0) {
Character.Move(transform.TransformDirection(Move));
2017-05-09 06:15:34 +02:00
Client.Send(PktType.MoveCreature, new MoveCreaturePkt(transform.TransformDirection(Move), Character.ID));
2017-05-08 23:03:02 +02:00
} else if (Character.Moving()) {
Character.Stop();
2017-05-09 06:15:34 +02:00
Client.Send(PktType.MoveCreature, new MoveCreaturePkt(new Vector3(), Character.ID));
2017-05-08 23:03:02 +02:00
}
} else if (Character.Moving()) {
// The debug console is open, stop the player.
Character.Stop();
}
}
}
}