- Home /
call float variable from 2 strings?
Hi, I need to figure out how to call a float variable from 2 strings. Here is my code to help your understand.
var money : float;
var Testprice : float = 1000;
function OnMouseDown () {
var purchase = gameObject.tag; //tag is "Test"
var purchasePrice = purchase + "price";
money = 3000;
if (money => purchasePrice) // i cant get this to work?
{
Invoke( purchase, 0f );
}
}
Comment
Answer by Kiwasi · Jul 31, 2014 at 07:30 PM
You could use reflection (google it)
Or you could create a helper method
private float GetPrice (string itemName){
switch (itemName){
case "TestPrice" :
return testPrice;
case "OtherPrice" :
return 572;
}
return 0;
}
i cant get the helper method to work, i get the error "float is not a valid macro"
function On$$anonymous$$ouseDown () {
var purchase = gameObject.tag;
var purchasePrice = purchase + "price";
money = 3000;
float GetPrice (purchasePrice){
switch (purchasePrice) {
case "Testprice" :
return 1000;
case "Test2price" :
return 2000;
}
return 0;
}
Debug.Log(GetPrice);
if (money == GetPrice)
{
Invoke( purchase, 0f );
}
}
Your answer
Follow this Question
Related Questions
Ball not going to directions 0 Answers
Resticing variables to whole numbers 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Public and Static Variables 2 Answers
Assigning varaibles to prefabs 1 Answer