UsingOtherComponents
using UnityEngine;
using System.Collections;
public class UsingOtherComponents : MonoBehaviour
{
public GameObject otherGameObject;
private AnotherScript anotherScript;
private YetAnotherScript yetAnotherScript;
private BoxCollider Boxcol;
void Awake()
{
anotherScript = GetComponent<AnotherScript>();
yetAnotherScript = otherGameObject.GetComponent<YetAnotherScript>();
Boxcol = otherGameObject.GetComponent<BoxCollider>();
}
void Start()
{
Boxcol.size = new Vector3(3, 3, 3);
Debug.Log(“The player’s score is “ + anotherScript.playerScore);
Debug.Log(“The player has died “ + yetAnotherScript.numberOfPlayerDeaths + ” times”);
}
}
YetAnotherScript
using UnityEngine;
using System.Collections;
public class YetAnotherScript : MonoBehaviour
{
public int numberOfPlayerDeaths = 3;
}
AnotherScript
using UnityEngine;
using System.Collections;
public class AnotherScript : MonoBehaviour
{
public int playerScore = 9000;
}