Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by FuPro · May 13, 2015 at 08:33 PM · c#2dbutton

Button don't work?

Hello everyone. I've started programming with unity3D, so I am beginner and not really good. I tried to create a "Jump" button for an Android App, but everything I tried just failed. First I tried Input.touchCount, but then I could jump only one or endless times. Then I tried TouchPhase.began, but nothing happen if I click on the button. Finally I tried HitTest and again, nothing happen. I don't know any other solution. Could you help me? Code:

 using UnityEngine;
 using System.Collections;
 
 public class Jump : MonoBehaviour {
     public bool var;
     void Update()
     {
         foreach(Touch touch in Input.touches)
         if(this.GetComponent<GUITexture>().HitTest(touch.position))
         {
             var = true;
         }
     }
 }

('var' is used in another script for jumping) Thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tebandesade · May 13, 2015 at 09:15 PM

Hi well what I did here was have a Gameobject with a script called test

 sing UnityEngine;
 using System.Collections;
 
 
 
 public class Test : MonoBehaviour {
 
     public GameObject test ;
     public bool toto;
 
 
     // Use this for initialization
     void Start () 
     {
 
     }
     
     // Update is called once per frame
     void Update () 
     {
         jump ();
         //Debug.Log (toto);
     }
 
     public void cambiarBool()
     {
             if (toto) {
             toto = false;
             toto=true;
             }
     }
 
     public void jump()
     {
         if (toto == false && Input.GetMouseButtonDown(0)) 
         {
             test.transform.Translate(Vector3.up );
         }
     }
 }
 

That at the same time had a GameObject called Test that is the same gameobject , I referenced the GO just by dragging the GO from the Hierarchy view to the slot in the editor that whas created from the line of code "public GameObject test ; "( I like referencing GO like this) . Afterwards I created a UI.Button and in the button inspector I went to the On Click () property and below where you choose if you want (Off, editor and runetime and runetime) I referenced the gameobject that had the script Test . Next, next to the where you choose those options I listed before, you choose the script where you have your commands (in my case Test ) so I can access all the PUBLIC declared functions, in my case the cambiarBool (this in spanish means change bool) so I can afterwards proceed to jump. alt text

I kinda did something sloppy where my bool changes from true to false ( so a "trigger" event occurs) but also, made sure that to jump, the left mouse button had to be pressed at the same time because otherwise it would move up always.


captura-de-pantalla-2015-05-13-a-las-41128-pm.png (93.9 kB)
Comment
Add comment · Show 2 · 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 tebandesade · May 13, 2015 at 09:20 PM 0
Share

Actually you can just go ahead and skip the bool change and just add the Onclick() function to jump() and if (Input.Get$$anonymous$$ouseButtonDown(0))) ......

avatar image FuPro · May 17, 2015 at 03:13 PM 0
Share

If I create a button, I also create a canvas and a text, but the canvas and the text need a runtime script in scene file. I don't know what I should use as runtime script, but if I delete them, I can click everywhere and I will jump. But I can't jump while I press with my other finger to control. I am a beginner and it's hard to do it the first time, so it would be nice, if you can help me.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make a script for "jetpack" boost animation 1 Answer

Something wrong with my movement script... 3 Answers

How do I access a GUITexture from C#? 0 Answers

Distribute terrain in zones 3 Answers

Unity 2D - Basic Button Movement 1 Answer


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