I’m having a problem that is driving me insane. I’ve debugged the script manually and could not find the problem. The error that I am getting is this:
UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
And the code:
using UnityEngine;
using System.Collections;
public class UIController : MonoBehaviour {
public GameObject player;
private PlayerBehaviour playerScript;
void Start () {
player = GameObject.Find ("Player");
playerScript = player.GetComponent<PlayerBehaviour>();
Debug.Log (playerScript.health);
}
// Update is called once per frame
void Update () {
}
}