Results 1 to 4 of 4
  1. #1
    general656's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    7
    Reputation
    10
    Thanks
    0
    My Mood
    Amazed

    Question In Game Variable not Workin' ...

    I just want when I push "F" the flashlight to turn on ONLY if I have 5 points . And when I push "O" to gain Points so I can use the flashlight . But if I try the "int points = 0 " to make it "static int points = 0" it doesn't work . It sends me an error "Unexpected Symbol 'static' . In this code I put the 'static' in brackets just to remind you I have used it without and with it in this code .
    Code:
    using UnityEngine;
    using System.Collections;
    
    public class flashing : MonoBehaviour
    {
        void Update()
        {
            (static) int points = 0;
            
            if (Input.GetKeyDown(KeyCode.O))
                points++;
                
            if (Input.GetKeyDown(KeyCode.F) && points == 5)
            {
                points = 0;
                light.enabled = !light.enabled;
            }
        }
    }

  2. #2
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Try defining the points outside of the function then as part of the class. I'm not sure if Unity puts limitations on the code it runs inside its scripts or not.
    Also you should check if greater than or equal to 5 for the flash light. Since you don't cap how much points O will generate.

    Code:
    using UnityEngine;
    using System.Collections;
    
    public class flashing : MonoBehaviour
    {
        private static int _points;
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.O))
                _points++;
                
            if (Input.GetKeyDown(KeyCode.F) && _points >= 5)
            {
                _points -= 5;
                light.enabled = !light.enabled;
            }
        }
    }
    Last edited by atom0s; 06-20-2013 at 12:13 PM.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  3. #3
    general656's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    7
    Reputation
    10
    Thanks
    0
    My Mood
    Amazed
    Quote Originally Posted by atom0s View Post
    Try defining the points outside of the function then as part of the class. I'm not sure if Unity puts limitations on the code it runs inside its scripts or not.
    Also you should check if greater than or equal to 5 for the flash light. Since you don't cap how much points O will generate.

    Code:
    using UnityEngine;
    using System.Collections;
    
    public class flashing : MonoBehaviour
    {
        private static int _points;
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.O))
                this._points++;
                
            if (Input.GetKeyDown(KeyCode.F) && this._points >= 5)
            {
                this._points -= 5;
                light.enabled = !light.enabled;
            }
        }
    }
    Nope ... it's not working too ... -_- This unity ... The error :
    "CS0176: Static member 'flashing.points' cannot be accessed with an intance reference, qualify it with a type name instead"
    Thank you for the supporting dude ... But I want to fint a solution to this issue very much . If I will find a solution I will be able to do more things . I am a nearly beginner and I want to learn more .

  4. #4
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Oh blah that was my bad, and what I get for not thinking after just waking up.
    Remove the this. keywords from the _points given that it is static.

    Updated the code above.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

Similar Threads

  1. [Help] injector not workin
    By loonylezzy in forum CrossFire Hacks & Cheats
    Replies: 12
    Last Post: 10-24-2009, 12:22 PM
  2. public hack not workin proply
    By lamont in forum CrossFire Hacks & Cheats
    Replies: 0
    Last Post: 07-16-2009, 06:28 PM
  3. Swear in a game room. [Not Crtl+BackSpace]
    By Raymondx3 in forum Combat Arms Glitches
    Replies: 7
    Last Post: 06-28-2009, 03:24 AM
  4. crossfire hacks gettin not workin QQ
    By retard223 in forum CrossFire Hacks & Cheats
    Replies: 17
    Last Post: 06-03-2009, 08:09 PM
  5. Make It Clear For CA Not Workin!
    By DurangoSan in forum Combat Arms Hacks & Cheats
    Replies: 19
    Last Post: 05-31-2009, 11:41 AM

Tags for this Thread