Ok so what i have is 2 seperate scenes. The actual “game scene” where you kill things and pickup points. I have it so that once you have picked up all the points in that scene you will go to the Shop Menu through Application.LoadLevel. In the shop menu right now there is 1 button which i am trying to make it so that the variable of the “shoot” script in the “game scene” that determines how far you shoot
will be increased if you have enough points. I also want that increase to stay on future levels like an upgrade. The errors I am getting with the ShopMenu script is
Assets/Scripts/ShopMenu.js(15,34): BCE0020: An instance of type ‘Points’ is required to access non static member ‘score’.
Assets/Scripts/ShopMenu.js(17,35): BCE0020: An instance of type ‘shoot’ is required to access non static member ‘gunRange’.
My Shop Menu script is
function OnGUI () {
GUI.Box (Rect (10,10,250,90), "Shop Menu");
if (GUI.Button (Rect (20,40,200,20), "Longer Range: 15 Points ")) {
Debug.Log ("Bought Longer Range");
BuyRange();
}
}
function BuyRange() {
var points = gameObject.Find("Player").GetComponent(Points);
var pointsscore = Points.score;
var shootrange = gameObject.Find("TankTurret").GetComponent(shoot);
var shootingrange = shoot.gunRange;
if (pointsscore >= 15) {
shootrange.gunRange = 50;
}
}
The shoot script is
var gunRange = 40;
var bullet : Rigidbody;
function Update () {
if (Input.GetKeyDown ("space"))
{
var clone : Rigidbody;
clone = Instantiate(bullet, transform.position, transform.rotation);
//Give the cloned bullet velocity along z axis
clone.velocity = transform.TransformDirection (Vector3.up * gunRange);
}
}
The Points script
var score = 0;
function OnTriggerEnter ( other : Collider ) {
if (other.tag == "Points") {
score += 5;
Destroy (other.gameObject);
}
}
function OnGUI (){
GUI.color = Color.red;
GUI.Box (Rect(25,25,100,30), "Points: "+score);
}
function Update () {
if (score==15) {
loadShopMenu();
}
}
function loadShopMenu ()
{
yield WaitForSeconds(3);
Application.LoadLevel(2);
}