Access Player Using HookPlayer
How to access the player from your own scripts using C#
Last updated
using UnityEngine;
public class TutorialHookPlayer : MonoBehaviour
{
}using GameCreator.Characters;
using GameCreator.Core.Hooks;public GameObject playerGo;// IHook player = HookPlayer.Instance;
var player = HookPlayer.Instance;public GameObject playerGo: // Method 1
//Method 2
void GetPlayerGameObject()
{
GameObject playerGo2 = HookPlayer.Instance.gameObject; // same as 1
}public GameObject player;
void GetComponentsMethod1()
{
// var component = player.GetComponent<PlayerCharacter>();
PlayerCharacter component = player.GetComponent<PlayerCharacter>();
// Do stuff with component.xxx
}public PlayerCharacter player;
void GetComponentsMethod2()
{
// Do stuff with player.xxx
}void GetComponentsMethod3()
{
PlayerCharacter player = HookPlayer.Instance.GetComponent<PlayerCharacter>();
// PlayerCharacter player = HookPlayer.Instance.gameobject.GetComponent<PlayerCharacter>();
// Do stuff with player.xxx
}