What is wrong? It cant acess the cost in TowerScript (ts) threw TowerSpot:
bm.selectedTower.GetComponent<.TowerScript>().cost
using UnityEngine;
public class TowerSpot : MonoBehaviour
{
void OnMouseUp()
{
Debug.Log("TowerSpot Clicked!");
BuildingManager bm = GameObject.FindObjectOfType<BuildingManager>();
if(bm.selectedTower != null)
{
ScoreManager sm = FindObjectOfType<ScoreManager>();
//cost cant be found! FIXME!
if(sm.money < bm.selectedTower.GetComponent<TowerScript>().cost)
{
Debug.Log("Not enough money");
return;
}
sm.money -= bm.selectedTower.GetComponent<TowerScript>().cost;
Instantiate(bm.selectedTower, transform.position, transform.rotation);
Destroy(transform.gameObject);
}
}
}
using UnityEngine;
public class BuildingManager : MonoBehaviour {
public GameObject selectedTower;
}
using UnityEngine;
public class TowerScript : MonoBehaviour
{
public int cost = 5;
}