void UpdateCost(){
GameObject towers = GameObject.FindGameObjectsWithTag(“Tower”);
int QuantityOfTowers = 0 ;
for(int i = 0; i<tower.Length;i++){
for(int c = 0; c<towers.Length;c++){
if(tower*.name == towers*
~~~c
.name){
QuantityOfTowers++;
}
}
HowMuchCosts = BackupHowMuchCosts*/this is the array im talking about/ + extraCost**QuantityOfTowers;
QuantityOfTowers = 0;
}
}
So, what i want is to index the system array (not that built in one, the System.Array one) so i can sum with other values, but it is not working. How do i index the arrays?
It would be good if i could convert the array to a builtin array or a generic list. I cannot make the array into a builtin array becouse i need that it has the same starter values of HowMuchCosts, and the builtin array just references and it has the same values of that array in all times, when a value of howmuchcosts changes, it also changes on that builtin array. Please help?
Entire Script:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class PlantTower : MonoBehaviour {
public Material StarterMaterial;
public Material MOMaterial;
public static PlantTower open;
public bool guienabled = false;
public GameObject[] tower;
public int[] HowMuchCosts;
public CameraSetter set;
public bool CanOpen = true;
public int[] extraCost;
private Array BackupHowMuchCosts;
void Awake(){
open = this;
Array.Copy (HowMuchCosts,BackupHowMuchCosts,HowMuchCosts.Length);
}
void OnMouseDown(){
if (set.GuialreadyOpened == false&& CanOpen == true) {
audio.Play();
guienabled = true;
set.GuialreadyOpened = true;
}
}
void OnMouseOver () {
if(set.GuialreadyOpened == false)
renderer.material = MOMaterial;
}
void OnMouseExit(){
if(set.GuialreadyOpened == false)
renderer.material = StarterMaterial;
}
void UpdateCost(){
GameObject[] towers = GameObject.FindGameObjectsWithTag("Tower");
int QuantityOfTowers = 0 ;
for(int i = 0; i<tower.Length;i++){
for(int c = 0; c<towers.Length;c++){
if(tower*.name == towers[c].name){
QuantityOfTowers++;
}
}
HowMuchCosts* = BackupHowMuchCosts* + extraCost**QuantityOfTowers;
QuantityOfTowers = 0;
}
}
void FixedUpdate(){
UpdateCost();
}
void OnGUI () {
if (guienabled == true && CanOpen == true &&set.English == true&&set.guiactive) {
GUI.Box (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 200, 200, 400), "Choose a Tower");
int i;
float y = 180;
for(i = 0; i<tower.Length;i++){
y -= 30;
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 - 10 - y, 150, 20), tower*.name+" ("+HowMuchCosts*+" GC)")) {
audio.Play();
if (Motor.Instance.GoldenCoins >= HowMuchCosts*) {
GameObject tow = (GameObject)Instantiate (tower*, transform.position + new Vector3 (0f, 3f, 0f), transform.rotation);
tow.GetComponent<Tower>().pad = gameObject;
string str1 = "(Clone)";
string str2 = tow.name;
tow.name = str2.Replace(str1,"");
Motor.Instance.GoldenCoins -= HowMuchCosts*;
set.GuialreadyOpened = false;
gameObject.renderer.enabled = false;
guienabled = false;
CanOpen = false;
renderer.material = StarterMaterial;
}
}
}
if (GUI.Button (new Rect (Screen.width / 2 - 11.5f + 88, Screen.height / 2 - 10 - 190, 23, 20), "X")) {
audio.Play();
guienabled = false;
set.GuialreadyOpened = false;
renderer.material = StarterMaterial;
}
} else if (guienabled == true &&CanOpen == true&& set.English == false&&set.guiactive) {
GUI.Box (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 200, 200, 400), "Escolha a Torre");
int i;
float y = 180;
for(i = 0; i<tower.Length;i++){
y -= 30;
Tower towe = tower*.GetComponent<Tower>();
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 - 10 - y, 150, 20), towe.NIP+" ("+HowMuchCosts*+" CO)")) {
audio.Play();
if (Motor.Instance.GoldenCoins >= HowMuchCosts*) {
GameObject tow = (GameObject)Instantiate (tower*, transform.position + new Vector3 (0f, 3f, 0f), transform.rotation);
tow.GetComponent<Tower>().pad = gameObject;
Motor.Instance.GoldenCoins -= HowMuchCosts*;
set.GuialreadyOpened = false;
gameObject.renderer.enabled = false;
guienabled = false;
CanOpen = false;
renderer.material = StarterMaterial;
}
}
}
if (GUI.Button (new Rect (Screen.width / 2 - 11.5f + 88, Screen.height / 2 - 10 - 190, 23, 20), "X")) {
audio.Play();
guienabled = false;
set.GuialreadyOpened = false;
renderer.material = StarterMaterial;
}
}
}
}
And im getting this error:
Assets/Scripts/PlantTower.cs(51,43): error CS0021: Cannot apply indexing with to an expression of type `System.Array’*
~~~