Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by AndrewLackey_97 · Nov 27, 2017 at 05:11 AM · buttonsetactiveif statement

how to do a if statement to activate and deactivate a button

So I wanted to add on to the roll-a-ball tutorial by adding some more complex levels to it. I am using buttons to go between the different scenes that have the different levels on them. What I have setup so far is to have my if statement refer to how many items have been collected (in this case two for the sake of time) to determine if I have won and to therefore pop up the button to change scenes. I am using "continueBtn.SetActive(true)/(false);" to deactivate and activate the button therefore "popping" it up. (refer to my script that I will be posting below if you are confused) My problem is that It won't be deactivated when I don't have those two items collected and it won't be active when I do have them. I have tried to replace the false with true and I have tried to delete the "else" portion of the statement and nothing truly works. I know my problem isn't that the script isn't attached to the button itself because I have checked that many times and with some of my experiments of deletion and replacement It sometimes is popped up before I even get those two items. (to understand what I have tried and and what I haven't look at my short vid (I will post a link below). THANKS FOR TAKING YOUR TIME TO HELP ME!! :)

Here is my short vid (I highly recommend you to watch it) : https://youtu.be/tryPRDXJH8k

You guys helped me last time I had a problem so I'm going to put your name here @NorthStar79 @EdwinChua (everybody ignored my last question once somebody typed one response but when I replied with their solution not working and put @their name they still didn't respond. So thats why im reposting this question).

Here is my script (the if then statement is at the bottom):

 public class PlayerController : MonoBehaviour {
 public float speed;
 public float time = 0;
 public Text countText;
 public Text winText;
 public int count;
 public GameObject ContinueBtn;
  

 private Rigidbody rb;
   

 void Start()
 {
     {
         rb = GetComponent<Rigidbody>();
         count = 0;
         SetCountText();
         winText.text = "";
         ContinueBtn.SetActive(false);
     }
 }


 void FixedUpdate()
 {
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");

         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

         rb.AddForce(movement * speed);
     }
 }


 void OnTriggerEnter(Collider other)
 {

     if (other.gameObject.CompareTag("Pick Up"))
     {
         other.gameObject.SetActive(false);
         count = count + 1;
         SetCountText();
     }
 }

 void SetCountText()
 {
     countText.text = "Count: " + count.ToString();
     if (count >= 18)
         winText.text = "You've won!";

     if (count >= 2)
     {
         ContinueBtn.SetActive(true);
     }
     else ContinueBtn.SetActive(false);
 } 
Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NorthStar79 · Nov 27, 2017 at 05:24 AM 0
Share

Hello and good morning. I am sorry to hear that you still couldn't solve your problem. as I said on Friday I couldn't response your comments because of weekends. if you attach your project file as Zip. I wish to take a look at it because we can not solve this with just you have provided us yet. normally we shouldn't ask project files but, as this is just a tutorial project, I guess it will not cause any harm.

avatar image AndrewLackey_97 NorthStar79 · Nov 27, 2017 at 06:33 AM 0
Share

Don't worry I got impatient and forgot you wouldn't be checking anything this past weekend. Sorry but I don't know how to make a zip file of my project and I don't know how to attach it to this comment. I don't see any options of how to add actual files. @NorthStar79

avatar image NorthStar79 AndrewLackey_97 · Nov 27, 2017 at 06:52 AM 0
Share

this section has a file size limit, so you can send a link via dropbox, Drive etc.

for getting your project file, just right-click any asset you have > show in explorer - then go to root directory you will see your project file. it should look like this : alt text

1.png (19.0 kB)
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NorthStar79 · Dec 08, 2017 at 08:05 AM

Hello , sorry for late response, i totally forgot your question :(

BTW fixed your continue button problem but i must say that there are a lot of other errors, but i believe you can fix them yourself.

here steps for how to fix it. first : you need to write correct next lvl name into continue button alt text

and then you need to assign button in player script too

alt text

thats all , also here a video how it works:

https://youtu.be/yU_9WOnqaBA

if this answer helped please consider marking as correct, this way anyone else who looking for the same question can easily find this answer. This is essential for this community.


2.png (14.4 kB)
1.png (7.2 kB)
Comment
Add comment · Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AndrewLackey_97 · Dec 08, 2017 at 06:02 PM 0
Share

O$$anonymous$$G how did you get that to work?? I did what you said at least I think so here is a vid to show what I changed but i'm still confused on why it won't work for me. I am however very happy that you got it to work because that means I should. thanks again for your time, I know this is probably getting annoying for you but it is all much appreciated. https://youtu.be/dB5kq$$anonymous$$t$$anonymous$$ouc @NorthStar79

avatar image NorthStar79 AndrewLackey_97 · Dec 09, 2017 at 12:35 PM 0
Share

sorry my connection is too bad right now, i am at my annual vacation i couldn't upload picture, (it took about 1 hour to watch your video because connection) you should not attach player controller to your button. if this not solve your problem i will upload fixed version of project when i get s good connection(probably monday)

avatar image AndrewLackey_97 NorthStar79 · Dec 09, 2017 at 05:22 PM 0
Share

It didn't fix my problem. I can definitely wait if you just give me instructions on how to use the project file that you give me on monday. I can tell you enough how thankful I am for what you are doing for me. @NorthStar79

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

133 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to detect if a button was pressed? 1 Answer

How to keep bool true even when other method try to set it off 0 Answers

If & Else If with == and && not working 0 Answers

Other way to write a code 0 Answers

SetActive not reacting on Buttonclick 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges