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 junaid_471 · May 14, 2016 at 09:42 AM · racegui button

race gui button doesnt work

i am developing 3D rickshaw racing android game.when i press race button works fine and after brake button press works fine and after pressing brake button press race button doesn't work.these are GUI button made in code in C#. using UnityEngine; using System.Collections;

public class GUI_button : MonoBehaviour {

 public GameObject RickFULL;

 //intialization for Sound tracks Obj
 public GameObject race_paddle_snd;
 public GameObject brake_paddle_snd;


 //initailization for the GUI Button
 public Texture2D race_paddle_texture= null;
 public Texture2D brake_paddle_texcture = null;
 public Texture2D Back_to_Menu_texture = null;

 public GUIStyle race_paddle_style = null;
 public GUIStyle brake_paddle_style = null;
 public GUIStyle Back_to_Menu_style = null;

 bool Back_to_Menu_pressed = false ;



 Rect race_paddle_texture_pos = new Rect(Screen.width - 100, Screen.height - 130, 100, 100);
 Rect brake_paddle_texture_pos = new Rect(Screen.width- 1200, Screen.height -130 ,100,100);
 Rect Back_to_Menu_texture_pos = new Rect(Screen.width - 100, 20 ,70,40);

 //Intialization for the Wheel Collider
 public GameObject wheel_front_collider;
 public GameObject wheel_back_left_collider;
 public GameObject wheel_back_right_collider;
 float fmaxTorque = 3000.0f;

 //initialization for the wheels transform rotation
 public GameObject wheel_front_transform;
 public GameObject wheel_back_left_transform;
 public GameObject wheel_back_right_transform;




 //intialization for steer Handling Speed
 float lowest_steer_at_speed= 50.0f;
 float lowest_speed_steer_angle = 10.0f;
 float highest_speed_steer_angle = 01.0f;
 float deaccelerationSpeed =200000.0f;        //Decreasing the acceleration in case the race is not pressed


 Vector3 deltaVect3 = new Vector3 (0,0,0);
 float deltaAng;

 //GUI Function body Intailization
 bool race_button_pressed = false;
 bool brake_button_pressed = false;
 //void race_button_pressed();
 //void brake_button_pressed();


 void AccelerometerMove()
 {
     float x = 0.0f;
     x = Input.acceleration.x;
     //current_steer_angle = y;

     //Debug.Log ("X = " + x);
     wheel_front_collider.GetComponent<WheelCollider> ().steerAngle = 100 * x;//current_steer_angle;

     if(race_button_pressed==true)
     {
         wheel_back_right_collider.GetComponent<WheelCollider> ().motorTorque = -fmaxTorque;
         wheel_back_left_collider.GetComponent<WheelCollider> ().motorTorque = -fmaxTorque;
         race_paddle_snd.SetActive (true);
         Debug.Log ("race_button_pressed");
         //race_button_pressed = false;
     }

     else 
     {
         wheel_back_left_collider.GetComponent<WheelCollider> ().motorTorque = 0.0f;
         wheel_back_right_collider.GetComponent<WheelCollider> ().motorTorque = 0.0f;
         race_paddle_snd.SetActive (false);
     }





     if (brake_button_pressed == true) {
         wheel_back_right_collider.GetComponent<WheelCollider> ().brakeTorque = deaccelerationSpeed;
         wheel_back_left_collider.GetComponent<WheelCollider> ().brakeTorque = deaccelerationSpeed;    
         brake_paddle_snd.SetActive (true);
         Debug.Log ("brake_button_pressed");
     }
     else 
     {
         brake_paddle_snd.SetActive (false);    
     }

} void FixedUpdate() { AccelerometerMove (); }

 void Update()
 {
     //start---> Rotaion of wheels
     wheel_back_left_transform.GetComponent<Transform> ().Rotate (wheel_back_left_collider.GetComponent<WheelCollider>().rpm/60*360*Time.deltaTime,0,0);
     wheel_back_right_transform.GetComponent<Transform> ().Rotate (wheel_back_right_collider.GetComponent<WheelCollider>().rpm/60*360*Time.deltaTime,0,0);


     //start---> Steer Angle of front Wheel

     deltaAng = (wheel_front_collider.GetComponent<WheelCollider>().steerAngle)-(wheel_front_transform.GetComponent<Transform>().localEulerAngles.z);
     deltaVect3.Set (0,deltaAng,0);

     wheel_front_transform.GetComponent<Transform> ().Rotate (wheel_front_collider.GetComponent<WheelCollider>().rpm/60*360*Time.deltaTime,deltaAng,0);
     wheel_front_transform.GetComponent<Transform> ().localEulerAngles = deltaVect3;

 }
 void Start()
 {
     RickFULL.GetComponent<Rigidbody> ().centerOfMass = new Vector3(0,-2,0);
     race_paddle_snd.SetActive (false);
     brake_paddle_snd.SetActive (false);    
     //Back_to_Menu_pressed = false;


 }




 private void OnGUI()
 {

     if (GUI.RepeatButton (race_paddle_texture_pos, race_paddle_texture,race_paddle_style))
     {
         race_button_pressed = true;
     }
     else
     {
         race_button_pressed = false;
     }

     if (GUI.RepeatButton (brake_paddle_texture_pos, brake_paddle_texcture,brake_paddle_style)) {
         brake_button_pressed = true;
     } else {
         brake_button_pressed = false;
     }



     if (GUI.Button (Back_to_Menu_texture_pos, Back_to_Menu_texture,Back_to_Menu_style)) 
     {
         //Back_to_Menu_pressed = true;
         Application.LoadLevel ("menu");
         //(GUI.Button (Back_to_Menu_texture_pos, Back_to_Menu_texture)) = false;
         Debug.Log("Back_to_Menu_pressed = true");
     }

 }

 }
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

0 Replies

· Add your reply
  • Sort: 

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

SCORING DRIFT POINTS 0 Answers

about race game’s skip race function. 0 Answers

How do i spawn an object with a button press? 3 Answers

how to do unity pull-down menu plz like picture for unity gui system 1 Answer

unable to play aanimation using gui button please help am just a beginner 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