[C#] If statment not executing?

I have a “Temperature” script attached to each player object. Each player also has the tag “Player”. In the scene, I have a object with the following script attached.

public class Fire : MonoBehaviour {

	public Temperature ph;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {

		GameObject[] players = GameObject.FindGameObjectsWithTag ("Player");
		for (int i=1; i < players.Length; i++) {
			if (Vector3.Distance (players*.transform.position, transform.position) < 10) {*
  •  		Debug.Log ("Player Near Fire");*
    

_ GameObject go = players*;_
_
ph = (Temperature)_
_
go.GetComponent (typeof(Temperature));_
_
ph.ChangeTemp(2);_
_
}_
_
}_
_
}_
_
}_
Here is the “ChangeTemp” function
_
public void ChangeTemp(int temper) {_
_
temp += temper;_
_
}*_
This should be working, but it prints nothing to the log, nothing happens period.
Thanks for any help!

void Update () {

	 players = GameObject.FindGameObjectsWithTag ("Player");
		for (int i=0; i < players.Length; i++) {
			if (Vector3.Distance (players*.transform.position, transform.position) < 10) {*
  •  		Debug.Log ("Player Near Fire");*
    

_ GameObject go = players*;_
_
ph = go.GetComponent();_
_
ph.ChangeTemp(2);_
_
}_
_
}_
_
}*_

Your code looks fine to me, makes sure you saved the label unto the players. This seems to be the most likely failure. Also make sure you didn’t type a space in the tag anywhere, the tags need to be exact.

I’m kind of amazed that script compiles at all, looking at this line:

ph = (Temperature)

…?

Is the for loop running?
Try moving the Debug.Log out of the if statement.

Also the for loop is starting at 1. Is that done on purpose?

In the top right of the console window, you can turn off normal, warning and error logs. Have you by accident turned off normal logs?

The button with the white speech bubble should look pressed.

I just edited your script to see why it didn’t fired the if statement. I edited it a bit and it should work now.

 using UnityEngine;
    using System.Collections;
    
    public class Fire : MonoBehaviour {
    
    	GameObject[] players;
           public Temperature ph;
    
    	// Use this for initialization
    	void Start () {
    	
    	}
    	
    	// Update is called once per frame
    
    	void Update () {
    		
    		players = GameObject.FindGameObjectsWithTag ("Player");
    		for (int i=0; i < players.Length; i++) {
    		float dist =Vector3.Distance (players*.transform.position,            transform.position);*
  •  	print (dist);*
    
  •  	if (dist < 10) {*
    
  •  		Debug.Log ("Player Near Fire");*
    

_ GameObject go = players*;_
ph = (Temperature)
go.GetComponent (typeof(Temperature));
ph.ChangeTemp(2);
_
}_
_
}_
_
}_
_
}*_

_*What I did was setting Vector3.Distance to a float called dist. And let it print each value between object 1 and its own each frame. Then if dist was smaller than 10 it would print “player near fire”. http://docs.unity3d.com/ScriptReference/Vector3.Distance.html*_

I got it to work, I just searched for a single player instead of the table.

Can’t you find the gameobjetcs in the start(), instead of calling it everytime in update.
Take the reference of the game objects in start() it self.