I have two buttons and a button manager script attached to left and right button.
I have a variable num =1;
i wana increase num by 1 when i press the right button and decrese when i press left.
However when i press right button it does increases by 1 but when i press left button the count starts from 1 again and not where i left it when i had pressed right button.
Any1 knows how to fix this
That sounds like a problem that you should be able to figure out yourself by looking at your code line by line and making yourself aware of what each line does.
The reason it does what it does, is in all likelyhood that you programmed it that way.
You should give yourself another chance at fixing this yourself, it will be a rewarding experience if you do it on your own. If you really can’t figure it out, post the code here (in code tags!) and explain where exactly you don’t understand what it does.
private int nm = 1;
public void slide()
{
if (nm !=4 && gameObject.name==“slider_r”) {
nm+=1;
print (nm);
}
if ( gameObject.name==“slider_l”) {
nm-=1;
print (nm);
}
}
Heres code. Its on both buttons slider_r and slider_l
When i press slider_r button twice nm is 3 as expected, but now if i press slider_l button once nm should be 2 but it comes as 0.
When I said you should code tags, I meant posting your code like this:
[code] your code goes here [/ code] <-- // but remove the space before 'code' in the closing tag!!! I just had to put that there so it visible at all.
It makes code snippits waaaaay more readable and increases the likelyhood of you getting an answer to your question by a lot.
private int nm = 1;
public void slide()
{
if (nm !=4 && gameObject.name=="slider_r") {
nm+=1;
print (nm);
}
if ( gameObject.name=="slider_l") {
nm-=1;
print (nm);
}
}
The first line is already wrong for what you want to achieve. You have a script and declare a private int variable for the script and initialize it to 1. Then you put instances of that script on your two sliders/buttons. Each one has their own private variable now. Those are not connected in any way. Each button deals with his number by the same logic, since they have the same script. So they both start out on 1. If you press the right button twice you start at 1 and make it 3. If you press the other button you start at 1 and it becomes 0 when you click once, just like you programmed it to.
You need to read this:
And learn some programming basics. This book has been recommended:
http://www.robmiles.com/c-yellow-book/
you didnt provide any answer to the problem.
Yeah he did, he told you what was causing the problem
1 Like
I’m kind of speechless to be honest…
2 Likes
can you people be eleborate this is begininger section.
Incase i am not clear what i wana acheive is when i press slider_r button twice it goes to 3 and when i press slider button_l once it should go to 2 and not zero as its currently hapenning.
He told you what was wrong, this is helping a beginner. He gave you the link to the tutorials, that is helping a beginner. This is not the ’ write a script for someone section’. If you don’t know how to fix it from what you were given then stop what you are doing & do the tutorials. Unity staff have taken the time to make them & have even done them in increasing levels of difficulty so you can learn more complex things as you progress, use them. Once you do you will be able to go back to this project & solve it yourself.
1 Like
I have already done tutorials and i am learning if u wana dont help or talk in riddels then fck off from beginners section.
Read his answer, he did help you. Then maybe get yourself a better attitude
1 Like
For real though, is he trolling us?
@skeleton_king These guys are just jerks. It’s ridiculous that they won’t make your game for you, and instead insist on pointing you towards the same resources for learning that everyone else uses. I personally feel you have what it takes to make it big in this industry, and for that, I believe you’re deserving of special treatment.
Here’s the answer to your question.
3 Likes
@Schneider21 Haha. So right, these goddamn n00bs are obviously not helping him!
For the record, I have no issue with people being new or asking for help. What I do have a problem with is the attitude some people demonstrate when asking for help from people who are volunteering their time to assist you.
Yeah I understand. I wasn’t saying the guy who asked the question was a noob, I was playing along - I was claiming that those who were assisting him were noobs for “obviously” not helping him 
1 Like
Darn Internet. Totally removing the tone from things.
1 Like
I know right lol I’m gunna re edit my post to make sure it sounds more like what it is intended to 