How To Access Variable From Another Script Unity | How To Get a Variable From Another Script In Unity Tutorial
Learn how to access variables from another script in Unity using public variables, GetComponent, and static variables. Perfect for beginners looking to manage data between scripts easily! 🚀
WATCH FULL TUTORIAL ON YOUTUBE
=========================================================
3 Unity Projects Only $50 - ON SALE!!!!
Contact: unitycoderz2022@gmail.com
=========================================================
Script:
GameManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public Text healthText;
private PlayerStats playerStats;
// Start is called before the first frame update
void Start()
{
playerStats = FindObjectOfType<PlayerStats>();
}
// Update is called once per frame
void Update()
{
healthText.text = "Health: " + playerStats.playerHealth;
}
}