YAWA code example

Example: YAWA

//https://docs.unity3d.com/ScriptReference/Transform-forward.html

using MLAPI;
using MLAPI.Messaging;
using MLAPI.NetworkVariable;
using UnityEngine;
using UnityEngine;
using System.Collections;//u can delete if you don't need to use the waitforseconds and coroutine

namespace AnotherUniverse
{
	public class AnotherForwardScript : NetworkBehaviour
	{
		[SerializeField]
		GameObject playerlookat;

		float m_Speed;

		bool debounce = true;

		void Start()
		{
			if (!IsOwner) { return; }

			m_Speed = 0.05f;
		}
		void Update()
		{
			if (!IsOwner) { return; }
			ForwardServerRpc();
		}

		IEnumerator ExampleCoroutine()//jump
		{
			yield return new WaitForSeconds(1.5f);
		}

		[ServerRpc]
		private void ForwardServerRpc()
		{
			ForwardClientRpc();
		}

		[ClientRpc]
		private void ForwardClientRpc()
		{
			if (NetworkManager.Singleton.ConnectedClients.TryGetValue(NetworkManager.Singleton.LocalClientId,
					out var networkedClient))
			{
				var player = networkedClient.PlayerObject.GetComponent<AnotherMyPlayer>();
				if (player)
				{
					if (Input.GetKey(KeyCode.W))
					{
						player.GetComponent<Rigidbody>().velocity += playerlookat.transform.forward * m_Speed;
					}
					if (Input.GetKey(KeyCode.S))
					{
						player.GetComponent<Rigidbody>().velocity += -playerlookat.transform.forward * m_Speed * 3;
					}
					if (Input.GetKey(KeyCode.A))
					{
						player.GetComponent<Rigidbody>().velocity += -playerlookat.transform.right * m_Speed;
					}
					if (Input.GetKey(KeyCode.D))
					{
						player.GetComponent<Rigidbody>().velocity += playerlookat.transform.right * m_Speed;
					}
					if (Input.GetKey(KeyCode.Space))
					{
						if (debounce == true)
						{
							debounce = false;
							player.GetComponent<Rigidbody>().velocity += playerlookat.transform.up * 0.05f;
							//StartCoroutine(ExampleCoroutine());
							debounce = true;
						}
					}
				}
			}
			print("PRESSED AND MOVING!");
		}
	}
}

Tags:

Misc Example