help with Unity Arrays video tutorial

Unity Arrays video tutorial
http://unity3d.com/learn/tutorials/modules/beginner/scripting/arrays

hi,
I created a script playerScript ( Attached to each player ) with “notHuman” property
but I need to know how to set the notHuman property to True just for the robot

playerScript.cs
public bool notHuman;

function Start () {
//find all players
//set notHuman to True just for the robot?
}

and
from the Arrays script,i need to know how to access ( get/set ) each player notHuman property individually

Arrays.cs
using UnityEngine;
using System.Collections;

public class Arrays : MonoBehaviour
{
public GameObject[ ] players;

void Start ()
{
players = GameObject.FindGameObjectsWithTag(“Player”);

for(int i = 0; i < players.Length; i++)
{
Debug.Log("Player Number “+i+” is named "+players*.name);*
//which player has the notHuman property with a positive value?

}
}
}

Is you bool exposed in the inspector ? If so check it as true.

I need to check ( access ) from another script or another object and not from the editor

try checking if the player is human in the loop function e.g.

for(int i = 0; i < players.Length; i++) {
     if (players[i].name == "Robot") {
           players[i].notHuman = true; //set the value of the player to not human.
     }
     Debug.Log("Player Number "+i+" is named "+players[i].name);
}

is this what you wanted? you question is very vague, try rewording it if this is the wrong answer

Because the players are system type gameObject, you will still need to reference the script component.

//------------//
for(int i = 0; i < players.Length; i++) {
  //------------//
  if(players[i].name == "Robot") {
    //------------//
    if(players[i].GetComponent(scriptName)) {
      //------------//
      players[i].GetComponent(scriptName).notHuman = true;
      //------------//
    }
    //------------//
  }
  //------------//
}
//------------//

(Tip) - It’s good to ask for the Component first so you avoid a null Reference exception.

true true, forgot about the “.GetComponent” when i wrote the code in the forum

lol - where it says scriptName, you have to put the name of your script. (playerScript)

Make sure your var is public.

I had already done this way:p
but the error appears anyway

is it not necessary to do this before instead of accessing the component directly?
var script : playerScript;

I’m getting errors with
players*.GetComponent(playerScript)[/B]*
this is what a i trying to do:
the scene has 3 cubes ( tagged: player ) representing the players and with playerScript script attached
and the canera with cameraPick script attached
i need to mark “as selected” the cube that is clicked
and only the selected cube should begin to rotate
but in the cameraPick script there are 3 errors related to playerScript being a type but used as variable
playerScript.cs
```
*using UnityEngine;
using System.Collections;

public class playerScript : MonoBehaviour {

public bool selected;

void Start () {
	 selected = false;
}

void Update () {

}

}
__
*__ __*cameraPick.cs*__ __**__
*using UnityEngine;
using System.Collections;

public class cameraPick : MonoBehaviour {

private Ray ray;
private RaycastHit hit;
public GameObject players;

void Start () {
players = GameObject.FindGameObjectsWithTag (“player”);
}

void Update () {

for(int i = 0; i < players.Length; i++){
if(Input.GetMouseButtonDown(0)){
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,100)) {
if(players[i].GetComponent(playerScript)){
players[i].GetComponent(playerScript).selected = true;
}
}
}

if (players[i].GetComponent(playerScript).selected == true){
    players[i].transform.Rotate(0,10,0);
	}
	
	}
}

}
__
```*__

In C# it should be GetComponent(typeof(playerScript)) but I would suggest using the generic overload which would be GetComponent()

this solved the problem of errors,thanks!

another problem :
now when I click on one of the cubes,the others are also selected,instead of just this one.

playerScript.cs

using UnityEngine;
using System.Collections;

public class playerScript : MonoBehaviour {
	public bool selected;
	
	void Start () {
	selected = false;
	}
	
	void Update () {
	if ( selected == true ){
	     transform.Rotate(0,10,0);
		}

	}
}

cameraPick.cs

using UnityEngine;
using System.Collections;

public class cameraPick : MonoBehaviour {
	
private Ray ray;
private RaycastHit hit;
public GameObject[] players;



void Start () {
players = GameObject.FindGameObjectsWithTag ("player");
}
	
void Update () {
		for(int i = 0; i < players.Length; i++){
			
			if(Input.GetMouseButtonDown(0)){
				
				ray = Camera.main.ScreenPointToRay (Input.mousePosition);
				  if (Physics.Raycast(ray,100)) {
					 if(players[i].GetComponent<playerScript>()){
						players[i].GetComponent<playerScript>().selected = true;
						if (players[i].GetComponent<playerScript>().selected == true){
                            Debug.Log("player selected name :" + players[i].name);
						}
					}
					
					}
				
				
			}
		}
	}
	
}

Your checking if your ray hits anything and not what player object it hits. You’re also setting selected to true and then checking if it’s true - so it always will be. Check out the Raycast overloads and use one of the ones that gives you back a RaycastHit object. This will be the object you clicked on.

thanks!