Array transform.position from another script
hi,my english is not very good so i`ll be directly.i create this code with an array on it to spawn multiples balls in my game,now i`m trying to access this array in a different script,the enemy script,this enemy should move arround depending balls array`s position.here is my spawnBallContoller script:
and here`s the enemyController script:
#pragma strict
var speed:float =10;
var ball:GameObject;
function Update () {
if(spawnBallController.ballArray.transform.position.y>transform.position.y){
transform.position = new Vector3(transform.position.x,transform.position.y+0.2,0);
transform.position.y = Mathf.Clamp(transform.position.y,-3.4,3.92);
}
if(spawnBallController.ballArray.transform.position.y<transform.position.y){
transform.position = new Vector3(transform.position.x,transform.position.y-0.2,0);
transform.position.y = Mathf.Clamp(transform.position.y,-3.4,3.92);
}
}
in unity i got this error: "transform" is not a member of unityengine.gameObject[]; hope someone can understend my problem,thanks
Answer by smnerat · Jul 23, 2016 at 08:12 PM
You need to specify which gameObject in the array you want to access.
int yourObjectID = 3;
if(spawnBallController.ballArray[yourObjectID].transform.position.y>transform.position.y){
Your answer
Follow this Question
Related Questions
Spawning limited GameObjects at a specific position not working 1 Answer
How can i use transform.position to a gameobject in an array? 1 Answer
When hitting border teleport bullet to player. 1 Answer
Cannot properly access player position 1 Answer
How to get the position of a gameObject based on its index in an array? 0 Answers