Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

'text' is not a member of 'int'.

Discussion in 'Editor & General Support' started by Deleted User, Apr 27, 2014.

  1. Deleted User

    Deleted User

    Guest

    Hi, I wanted to make a GUI with ammo, health and more.. But, it magically says 'text' is not a member of 'int'. It haven't said before... Sorry for my bad English...

    Here is the code:

    Code (csharp):
    1. #pragma strict
    2.  
    3. var reload : AudioClip;
    4. var reloadRate : float = 11.7;
    5. var ammo = 9;
    6. var totalAmmo = 18;
    7. var ammoGui : GUIText;
    8. private var nextFire : float = 0.0;
    9. private var t : Transform;
    10.  
    11. function Start () {
    12.     t = transform;
    13. }
    14.  
    15. function Update () {
    16.     if (Input.GetButton("Reload")  IsOkToShoot()) Shoot();
    17. }
    18.  
    19. function IsOkToShoot () : boolean {
    20.     var itsOk : boolean = false;
    21.     if (Time.time>nextFire) {
    22.        nextFire = Time.time + reloadRate;
    23.        itsOk = true;
    24.     }
    25.     return itsOk;
    26. }
    27.  
    28. function Shoot () {
    29.     AudioSource.PlayClipAtPoint(reload, t.position);
    30. }
    31.  
    32. function OnGUI () {
    33.     ammo.text = "Ammo: " + ammo + "/" + totalAmmo.ToString();
    34. }

    It's ammo GUI with reload sounds together. Please help... :(
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    You should use ToString(). You use it once when you should use it twice.
     
  3. Deleted User

    Deleted User

    Guest

    And please, where do I have to use it ? Or.. Can u edit that code for me ? :/ I'm lame at coding..
     
  4. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Line 33, you use ToString to convert totalAmmo from an int to a string. Now do the same for ammo.
     
  5. Deleted User

    Deleted User

    Guest

    Now, it tells me that error twice. :I
     
  6. Deleted User

    Deleted User

    Guest

    the problem isn't ToString(). You are trying to access .text on an interger on line 33.

    9.text = "some Text" - I hope you see that makes no sense. I guess you ment to write ammoGui .text = "some text"
     
  7. Deleted User

    Deleted User

    Guest

    Oh, thanks so much ! :)
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Another problem (though not one that's giving you an error): You are setting that in OnGUI, which is meant for functions like GUI.Label and GUILayout.Label. You should put that code in Update() or LateUpdate().
     
  9. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    D`Oh. Yeah, good point.