Search Unity

Change a boolean too float or Init

Discussion in 'Scripting' started by fredr92, Jul 27, 2014.

  1. fredr92

    fredr92

    Joined:
    Jul 8, 2013
    Posts:
    292
    Hi,

    I need some help With my Upgrade script.
    Im using the FPS constructor from the asset store and it comes With a Upgrade script, for Things for example a Scope or a rail/front grip .

    But it only allows you too have 1 Upgrade equiped at once and i think this is because it uses a boolean, it must be true or false. so the Publisher said on their documentation forum that you have too change it too a float value or a init if you want too have multipli Upgrades at once.

    Their site is Down, and the Publisher have moved on and can not be contacted anymore.
    And im having problems With having all the gear equipped at once on a rifle.

    So what is the difference between float and init ?
    And will it be easy to change the boolean With a float or init?

    I got this package when it was 70$, but its free now, so im gonna upload the script.

    Upgrade Script
    Code (csharp):
    1.  
    2. @HideInInspector var applied : boolean = false;
    3. var owned : boolean = false;
    4. var locked : boolean = false;
    5. var upgradeType : String;
    6. var upgradeName : String;
    7. var description : String = "Upgrade Locked";
    8. var lockedDescription : String;
    9. var buyPrice : float;
    10. var sellPrice: float;
    11. var scriptID : int = 0;
    12. var showInStore : boolean = true;
    13. private var gScript : GunScript;
    14. function Start () {
    15. Init();
    16. }
    17. function Init () {
    18. var gscripts = this.transform.parent.GetComponents.<GunScript>() as GunScript[];
    19. for(var q = 0; q < gscripts.length; q++){
    20. if(q == scriptID){
    21. gScript = gscripts[q];
    22. }
    23. }
    24. }
    25. function ApplyUpgrade () {
    26. var upgrades : Upgrade[];
    27. upgrades = this.transform.parent.GetComponentsInChildren.<Upgrade>();
    28. for(var i = 0; i < upgrades.length; i++){
    29. if(upgrades.upgradeType == upgradeType && upgrades != this)
    30. upgrades.RemoveUpgrade();
    31. }
    32. if(applied)
    33. return;
    34. this.SendMessage("Apply", gScript);
    35. applied = true;
    36. this.SendMessageUpwards("ApplyUpgrade");
    37. }
    38. function ApplyUpgradeInstant () {
    39. if(applied)
    40. return;
    41. BroadcastMessage("TempInstant");
    42. ApplyUpgrade();
    43. }
    44. function RemoveUpgrade () {
    45. if(!applied)
    46. return;
    47. this.SendMessage("Remove", gScript);
    48. applied = false;
    49. }
    50. function RemoveUpgradeInstant () {
    51. if(!applied)
    52. return;
    53. this.SendMessage("TempInstant");
    54. RemoveUpgrade();
    55. }
    56. function DeleteUpgrade () {
    57. RemoveUpgrade();
    58. Destroy(gameObject);
    59. }
    60.  



    GrapichObjectScript
    Code (csharp):
    1.  
    2. var obj : GameObject;
    3. var val : boolean = true;
    4. var instant : boolean = false;
    5. private var cache: boolean;
    6. private var applied : boolean = false;
    7. private var tempInstant : boolean = false;
    8.  
    9. function Apply () {
    10.     cache = obj.activeSelf;
    11.     if(val){
    12.         obj.SetActive(true);
    13.     } else {
    14.         obj.SetActive(false);
    15.     }
    16.    
    17.     var gos = obj.GetComponentsInChildren(Renderer);
    18.     var go : Renderer;
    19.    
    20.     if(!instant && !tempInstant) {  
    21.         for(go in gos){
    22.             go.enabled=false;
    23.         }
    24.     } else {
    25.         for( go in gos){
    26.             go.enabled=true;
    27.         }
    28.     }
    29.     tempInstant = false;
    30.    
    31.     transform.parent.BroadcastMessage("reapply", SendMessageOptions.DontRequireReceiver);
    32. }
    33. function Remove () {
    34.     obj.SetActive(cache);
    35.     if(instant || tempInstant){
    36.         var gos = obj.GetComponentsInChildren(Renderer);
    37.         var go : Renderer;
    38.         for( go in gos){
    39.             go.enabled=true;
    40.         }
    41.         tempInstant = false;
    42.     }
    43. }
    44.  
    45. function TempInstant () {
    46.     tempInstant = true;
    47. }
    48.  
     
    Last edited: Jul 27, 2014
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    floats (i.e. floating point numbers) are decimals,
    ints (i.e. integers) are whole numbers
    bools (i.e. boolean) are true/false, 1/0
     
  3. fredr92

    fredr92

    Joined:
    Jul 8, 2013
    Posts:
    292
    Thx for that explanation.
    Possible too get any help on how too be able too have more than 1 attachment equiped at once?
     
  4. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88