Well most of my script is working well, however the
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .5);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
part isn’t working. It does take away 500 money, but it doesn’t do anything inside that part. It doesn’t invoke the close function (which I know is working) and the text animation and audio doesn’t play. Any help would be appreciated, I’m in the final stretch of making this app and just as I’m about to finish I’m running into all of these seemingly impossible to solve errors. I assume that it may have to do with the comparison part.
Thanks, here is the part of the script that isn’t working:
if(hit.transform.name == "Buy upgrade" goodballupgrade1.gameObject.active == true PlayerPrefs.GetInt("Money") > 499){
PlayerPrefs.SetInt("Money",PlayerPrefs.GetInt("Money") - 500);
print (PlayerPrefs.GetInt("Money"));
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .6);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .55);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .5);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
if (PlayerPrefs.GetFloat("goodrandomvalue") == .5){
nomoney.animation.Play();
nomoney.audio.Play();
Invoke("close1", .2);
PlayerPrefs.SetInt("Money",PlayerPrefs.GetInt("Money") + 500);
}
}
if(hit.transform.name == "Cancel upgrade"){
Invoke("close1", .25);
}
if(hit.transform.name == "Clear all"){
PlayerPrefs.DeleteAll();
}
}
Thanks again, and here is the entire script:
private var hit : RaycastHit;
private var ray : Ray;//ray we create when we touch the screen
var clone1 : SpawnBall1;
var boughttext : GameObject;
var buysell : GameObject;
var behindobjects : GameObject;
var buy : GameObject;
var cancel : GameObject;
var nomoney : GameObject;
var textmoney : TextMesh;
var goldballupgrade1 : GameObject;
var goodballupgrade1 : GameObject;
//play boughtext animation and sound when item is bought.
var target1 : ballmade;
function FixedUpdate () {
textmoney.text = "Money: " + PlayerPrefs.GetInt("Money");
// PlayerPrefs.SetInt("Money",PlayerPrefs.GetInt("Money") + 1000);
if(iPhoneInput.touchCount == 1) {
ray = Camera.main.ScreenPointToRay(iPhoneInput.touches[0].position);
Debug.DrawLine(ray.origin,ray.direction * 10);
if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
Debug.Log(hit.transform.name);//Object you touched
//target1 = GameObject.Find("Ball Made").GetComponent(ballmade);
//clone1 = GameObject.Find("Cylinder Spawn 3").GetComponent(SpawnBall1);
}
if(hit.transform.name == "Menureturn"){
Application.LoadLevel("LoadMenu");
}
if(hit.transform.name == "greatball Upgrade"){
Invoke("open1", .15);
}
if(hit.transform.name == "goodball upgrade"){
Invoke("open2", .15);
}
if(hit.transform.name == "Buy upgrade" goldballupgrade1.gameObject.active == true PlayerPrefs.GetInt("Money") > 999){
// Upgrade goldball and take away money if it hasn't been upgraded more than twice, also do purchase animation
//add audio for everything here
}
if(hit.transform.name == "Buy upgrade" goldballupgrade1.gameObject.active == true PlayerPrefs.GetInt("Money") < 999){
nomoney.animation.Play();
nomoney.audio.Play();
Invoke("close1", .2);
}
if(hit.transform.name == "Buy upgrade" goodballupgrade1.gameObject.active == true PlayerPrefs.GetInt("Money") < 499){
nomoney.animation.Play();
nomoney.audio.Play();
Invoke("close1", .2);
}
if(hit.transform.name == "Buy upgrade" goodballupgrade1.gameObject.active == true PlayerPrefs.GetInt("Money") > 499){
PlayerPrefs.SetInt("Money",PlayerPrefs.GetInt("Money") - 500);
print (PlayerPrefs.GetInt("Money"));
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .6);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .55);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
if (PlayerPrefs.GetFloat("goodrandomvalue") == .7){
PlayerPrefs.SetFloat("goodrandomvalue", .5);
Invoke("close1", .1);
boughttext.animation.Play();
boughttext.audio.Play();
}
if (PlayerPrefs.GetFloat("goodrandomvalue") == .5){
nomoney.animation.Play();
nomoney.audio.Play();
Invoke("close1", .2);
PlayerPrefs.SetInt("Money",PlayerPrefs.GetInt("Money") + 500);
}
}
if(hit.transform.name == "Cancel upgrade"){
Invoke("close1", .25);
}
if(hit.transform.name == "Clear all"){
PlayerPrefs.DeleteAll();
}
}
}
function open1 () {
buysell.gameObject.active = true;
goldballupgrade1.gameObject.active = true;
behindobjects.gameObject.active = false;
}
function open2 () {
buysell.gameObject.active = true;
goodballupgrade1.gameObject.active = true;
behindobjects.gameObject.active = false;
}
function close1 () {
buysell.gameObject.active = false;
goldballupgrade1.gameObject.active = false;
goodballupgrade1.gameObject.active = false;
behindobjects.gameObject.active = true;
}
function nomoney1 () {
buysell.gameObject.active = true;
goldballupgrade1.gameObject.active = true;
behindobjects.gameObject.active = false;
}