Unityでジャンクゲームを作っているっぽい

会社帰りにGPD PocketにUnity入れてゲーム作ってます

【CEtest2】23_CorgiEngineでplayerのデータにアクセスしたい

基本的にBOSSのデータにアクセスする方法と同じだった
同じコンポーネントを使用しているので、どのオブジェクトにアクセスしたい?ってのを
明確にしないとアクセスできなかった

スクリプトを書く

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.CorgiEngine;	//CorgiEngineにアクセス

public class MyPlayer : MonoBehaviour{
	GameObject myPlayer;		//検索したPlayer入れる用
	private Health health;		//Health変数

	void Start(){
		myPlayer = GameObject.FindWithTag("Player");	//playerをtagで検索
	}

	void Update(){
		health = myPlayer.GetComponent<Health>();	//PlayerのHealthコンポーネント取得
		Debug.Log(health.CurrentHealth);		//とりあえず、テストで現在のHPを取得
	}
}

スクリプトアサイ

Playerのイロイロなコンポーネントと並べて配置
f:id:mekatamatama:20220405224825p:plain
こんな感じでHPが取得できた
youtu.be