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

    Question How Can I Make An InUnity3DGame Variable (Integer) [Help]

    I want to make a variable that will work In The Game . I mean I tryed this :
    Code:
    public class flashing : MonoBehaviour {
    	// Update is called once per frame
    	void Update()
        {
    		int points = 0;
    		if(Input.GetKeyDown(KeyCode.O)){
    			points += 1;
    		}
            if (Input.GetKeyDown(KeyCode.F))
            {	
                if(light.enabled == true && points == 5){
    				light.enabled = false;
    				points -= 5;
    			}
    			else if(light.enabled == false && points == 5){
    				
    				light.enabled = true;		
    				points -= 5;
    			}
    		}
    	}
    }
    and it didn't work . I don't know why . There were not any errors .
    The project I want to do is ... When I have 5 points to have the permission to close or open the lights , if not then I have to gather points pushing button "O" . Can anyone help me ?
    Last edited by general656; 06-15-2013 at 11:07 AM.

  2. #2
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    You are resetting points every call cause its defined inside the function and is not static. Try something like this:
    Code:
    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;
            }
        }
    }
    - 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
    I tryed with "static" keyword but unity sends me an error ... Unexpected Symbol 'static'

Similar Threads

  1. how can i make Exit button
    By sukh13 in forum WarRock - International Hacks
    Replies: 9
    Last Post: 10-21-2007, 02:18 AM
  2. How can i make a norwegian ts server??
    By xtrylanx in forum General
    Replies: 4
    Last Post: 08-19-2007, 06:05 PM
  3. how can i make a password on my hack
    By 123456789987654321 in forum WarRock - International Hacks
    Replies: 4
    Last Post: 06-24-2007, 04:50 PM
  4. How can i make a hack for WarRock?
    By tomva in forum General Game Hacking
    Replies: 4
    Last Post: 06-09-2007, 03:13 PM
  5. how can i make game hack?!!!!
    By UnknownID in forum General Game Hacking
    Replies: 2
    Last Post: 02-07-2006, 07:21 PM