- Home /
Why is my debug log not going through? (Trying to get a script to access a non static variable of another script.)
I'm not getting any parser errors and everything should be working fine. Below I'll post the script with the message that is failing to log and below that will be part of the script that I'm trying to access. Thank you for any help you can provide!
using UnityEngine; using System.Collections;
public class Sombrero : MonoBehaviour {
public GameObject Player;
void Start() {
}
void update() {
GameObject thePlayer = GameObject.Find("Triangle");
PlayerController playerscript = thePlayer.GetComponent<PlayerController>();
if (playerscript.health == 5) {
Debug.Log("Low HP");
}
}
}
using UnityEngine; using System.Collections;
And here is the list of variables from my player controller that I'm trying to access. My goal here is to add a function to my sombrero game object when the health reaches a certain point.
public class PlayerController : MonoBehaviour {
public float speed = 5f;
public float bumper;
float xmin;
float xmax;
public GameObject taco;
float projectileSpeed = 15f;
public float fireRate = 5f;
public float health = 5f;
}
Answer by jdean300 · May 19, 2016 at 05:09 AM
Unless what you posted has a typo, your update function needs a capital "U" to be automatically called by Unity.
If you don't know how to use the debugger, I suggest you read this and learn to use it - it'd make finding this type of problem very easy: https://unity3d.com/learn/tutorials/modules/beginner/scripting/monodevelops-debugger
Yeah the U in Update was just a typo. And I actually don't use $$anonymous$$ono develop. I was never able to get $$anonymous$$ono to work so I use something called $$anonymous$$icrosoft visual studio.
So does it work after fixing the typo?
If not, what is the value of health
in the PlayerController
(in the inspector)?
Visual Studio - even better. Figure out the debugger. Basically, click on the left side of the code window to place a breakpoint, click the green play button at the top the attach the debugger to unity, then play your game in the Unity editor. Your programs execution will stop wherever you placed your breakpoint (so place it at this update function), and you can see what is wrong by hovering your mouse over various variables.
Your answer
Follow this Question
Related Questions
Why isn't my animation state changing properly? 1 Answer
Switch vehicle 1 Answer
I am not able to reload a Scene a second time for my game 0 Answers
API Update ruined my scripts 1 Answer