Yep that was the problem. Now i’ve got another. It didn’t like me using an int[ ] to contain it so I swapped to the GameObject[ ] one instead. The problem I have not is that I still can’t get the length of the array.
Debug.Log(arrayLength.GetLength());
This doesn’t work. It comes up with two errors.
The best overload method match for ‘Unity.Engine.Debug.Log(object)’ has some invalid arguments.
Argument ‘#1’ cannot convert ‘method group’ expression top type ’ object’
I’m not sure if this will help. The reason I want to get the array is so i can cycle through the list of game objects creates in the BasePlatform script and apply changes to them.
using UnityEngine;
using System.Collections;
public class BasePlatform : MonoBehaviour {
public int platformAmount = 1;
public GameObject platform;
public GameObject[] platfromArray;
// Use this for initialization
void Start () {
platfromArray = new GameObject[platformAmount];
for(int i = 0; i < platformAmount; i++)
{
GameObject temp = Instantiate(platform) as GameObject;
//temp.transform.tag = "Platform " + i;
Debug.Log("Platform " + i);
platfromArray[i] = temp;
}
}
// Update is called once per frame
void Update () {
}
}
The changes I want to make need to be different each time applied. So what I want to do is loop through array and retrieve/edit the spawned objects in the script below.
using UnityEngine;
using System.Collections;
public class RandomSize : MonoBehaviour {
private float random_x;
private float random_y;
private float random_z;
private float random_zS;
private GameObject spawnRadius;
public float LengthRadius = 1.5f;
public float HeightRadius = 1.8f;
private float spawnPosX;
private float spawnPosY;
private float spawnPosZ;
GameObject []arrayLength;
//public Transform blah;
// Use this for initialization
void Start () {
random_z = Random.Range(-8, 8);
random_x = Random.Range(7, 10);
random_zS = Random.Range(4, 16);
random_y = Random.Range(spawnPosY, spawnPosY+0.5f);
spawnRadius = GameObject.FindWithTag("Spawn");
spawnPosX = spawnRadius.transform.position.x;
spawnPosY = spawnRadius.transform.position.y;
spawnPosZ = spawnRadius.transform.position.z;
GameObject thePlatform = GameObject.Find("Base Platform");
BasePlatform basePlatform = thePlatform.GetComponent<BasePlatform>();
arrayLength = basePlatform.platfromArray;
Debug.Log(arrayLength.GetLength);
}
// Update is called once per frame
void Update () {
//Debug.Log(arrayLength);
transform.localScale = new Vector3(random_x, 1f, random_zS);
transform.position = new Vector3(spawnPosX + random_x * LengthRadius, spawnPosY + random_y * HeightRadius+1.25f, spawnPosZ + random_z * LengthRadius);
}
}