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 shadab_badar · Jul 14, 2014 at 09:57 AM · guitexture

Problem touching the Guitexture and Texture 2D simultaneously

I have attached this script to a model of truck.

Its working fine when the GuiTexture and texture2D is being touched individually but

The problem lies when we are touching both of them simulataneously.

Touching the GuiTexture and then the Texture 2D is working fine but Touching the Texture

First and then the GuiTexture is not ok.

please help me out...

// // /*/

// for steering

 public var maximumAngle : float = 500f;

 public var wheelSize : float = 256f; 

 public var deltaPivot : Vector2 = Vector2.zero;

 public var wheelFreeSpeed : float = 200f;

 public var wheelTexture : Texture2D;

 // public var race : Texture2D;

 var race : GUITexture;

 private var wheelAngle : float;

 private var wheelPosition : Rect;

 private var wheelCenter : Vector2;

 private var wheelTempAngle : float;

 private var touchId : int = -1;


// for steering

     var SteerControl : GameObject;

     var rearWheel1 : WheelCollider;

     var rearWheel2 : WheelCollider;

     var frontWheel1 : WheelCollider;

     var frontWheel2 : WheelCollider;
 
     var steerings:GUITexture;

     var wheelFL : Transform;

     var wheelFR : Transform;

     var wheelRL : Transform;

     var wheelRR : Transform;
      
     var steer_max = 20;

     var motor_max = 40;

     var brake_max = 100;

     var steerSpeed = 20;

     private var wheelBeingHeld : boolean;

     static var steer = 0;

     private var forward = 0;

     private var back = 0;

     private var brakeRelease = false;

     private var motor = 0;

     private var brake = 0;

     private var reverse = false;

     private var speed = 0;


 

function Start()

{

wheelBeingHeld = false;

wheelPosition = new Rect(100,250,200,200 );

wheelCenter = new Vector2( wheelPosition.x + wheelPosition.width 0.5f, Screen.height - wheelPosition.y - wheelPosition.height 0.5f );

wheelAngle = 0f;

rigidbody.centerOfMass = Vector3(0, -0.05, 0);

}

function OnGUI() {

var theMatrix : Matrix4x4 = GUI.matrix;

GUIUtility.RotateAroundPivot( -wheelAngle, wheelPosition.center + deltaPivot );

GUI.DrawTexture( wheelPosition, wheelTexture );

GUI.matrix = theMatrix;

}

function FixedUpdate () { Debug.Log("forward "+forward);

   if(wheelAngle>-90 && wheelAngle<90)
   {
   steer=0;
   //forward=1;
   
   frontWheel1.steerAngle=0f;
   
   
   }
   
   if(wheelAngle>90 && wheelAngle<300)
   {
   steer=1;
   //forward=1;
   
    frontWheel1.steerAngle=-20f;
   }
   
    if(wheelAngle>-300 && wheelAngle<-90)
   {
   steer=-1;
  // forward=1;
    frontWheel1.steerAngle=20f;
   
   }
   
   
     if( wheelBeingHeld )
     {
         var touchPosition : Vector2;
  
         // Find the finger position on screen
         for( var t : Touch in Input.touches )
         {
             if( t.fingerId == touchId )
             {
                 touchPosition = t.position;
                
                 // If finger exists no more, release the wheel
                 if( t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled )
                 {
                     wheelBeingHeld = false;
                 }
             }
         }
       
 var wheelNewAngle : float = Vector2.Angle( Vector2.up, touchPosition - wheelCenter );
        
         // If touch is very close to the steering wheel's center, do nothing
         if( Vector2.Distance( touchPosition, wheelCenter ) > 20f )
         {
             if( touchPosition.x > wheelCenter.x )
                 wheelAngle -= wheelNewAngle - wheelTempAngle;
             else
                 wheelAngle += wheelNewAngle - wheelTempAngle;
         }
        
         // Make sure that the wheelAngle does not exceed the maximumAngle
         if( wheelAngle > maximumAngle )
             wheelAngle = maximumAngle;
         else if( wheelAngle < -maximumAngle )
             wheelAngle = -maximumAngle;
        
         wheelTempAngle = wheelNewAngle;
     }
     else // If wheel is not being held
     {
         // If a finger touches the wheel, update the status
         for( var t : Touch in Input.touches )
         {
         
       if( t.phase == TouchPhase.Began )
       
       {
       

if( wheelPosition.Contains( new Vector2( t.position.x, Screen.height - t.position.y ) ) ) { wheelBeingHeld = true; wheelTempAngle = Vector2.Angle( Vector2.up, t.position - wheelCenter ); touchId = t.fingerId; } } }

// If the wheel is rotated and not being held, rotate it to its default angle (zero)

         if( !Mathf.Approximately( 0f, wheelAngle ) )
         
         {
             var deltaAngle : float = wheelFreeSpeed * Time.deltaTime;
            
             if( Mathf.Abs( deltaAngle ) > Mathf.Abs( wheelAngle ) )
             {
                 wheelAngle = 0f;
                 return;
             }
            
             if( wheelAngle > 0f )
                 wheelAngle -= deltaAngle;
             else
                 wheelAngle += deltaAngle;
         }
     }// for steerins

 speed = rigidbody.velocity.sqrMagnitude;

 steer = Input.GetAxis("Horizontal");
 forward = Mathf.Clamp(Input.GetAxis("Vertical"), 0, 1);
 back = -1 * Mathf.Clamp(Input.GetAxis("Vertical"), -1, 0);
 
 
 

// for acceleration

var touchPosition1 : Vector2;

for( var t : Touch in Input.touches )

         {
         

if( t.phase == TouchPhase.Began || t.phase == TouchPhase.Stationary && race.HitTest(Input.mousePosition) )

                 {
                 
                    forward=1;
                    
                     rearWheel1.motorTorque = motor_max * motor;
                     
                     rearWheel2.motorTorque = motor_max * motor;
                     
                     rearWheel1.brakeTorque = brake_max * brake;
                     
                     rearWheel2.brakeTorque = brake_max * brake;
                       
                 }
                 
                
                 
                 
                 else
                 {
                 forward=0;
                 }

}// for loop closes

// for veerything to zero it can move forward or backward if(speed == 0 && forward == 0 && back == 0) { brakeRelease = true; }

 if(speed == 0 && brakeRelease)
  {
  
 if(back > 0) 
     {
  reverse = true; 
     }
 if(forward > 0) 
    {
  reverse = false; 
    }
 }
 

// if reverse is true then it make barke to forward if(reverse) { motor = -1 * back; brake = forward; } // ijn else brake is back else { motor = forward; brake = back; } if (brake > 0 ) { brakeRelease = false; };

 rearWheel1.motorTorque = motor_max * motor;
 rearWheel2.motorTorque = motor_max * motor;
 rearWheel1.brakeTorque = brake_max * brake;
 rearWheel2.brakeTorque = brake_max * brake;
 
 if ( steer == 0 && frontWheel1.steerAngle != 0) 
 {
  if (Mathf.Abs(frontWheel1.steerAngle) <= (steerSpeed * Time.deltaTime)) 
   {
   frontWheel1.steerAngle = 0;
   }
   else if (frontWheel1.steerAngle > 0) 
   {
   frontWheel1.steerAngle = frontWheel1.steerAngle - (steerSpeed * Time.deltaTime);
   } 
   else 
   {
   frontWheel1.steerAngle = frontWheel1.steerAngle + (steerSpeed * Time.deltaTime);
   }
 } 
 else 
 {
 frontWheel1.steerAngle = frontWheel1.steerAngle + (steer * steerSpeed * Time.deltaTime);
 if (frontWheel1.steerAngle > steer_max) { frontWheel1.steerAngle = steer_max; }
 if (frontWheel1.steerAngle < -1 * steer_max) { frontWheel1.steerAngle = -1 * steer_max; }
 }
 frontWheel2.steerAngle = frontWheel1.steerAngle;
 wheelFL.localEulerAngles.y = frontWheel1.steerAngle;
 wheelFR.localEulerAngles.y = frontWheel2.steerAngle;
 
 
 
 
 

// for just turning the whells

     wheelFR.Rotate(frontWheel1.rpm *6 * Time.deltaTime,0,0);
     wheelFL.Rotate(frontWheel2.rpm * 6 * Time.deltaTime,0,0);
     wheelRR.Rotate(rearWheel1.rpm * -6 * Time.deltaTime,0,0);
     wheelRL.Rotate(rearWheel2.rpm * -6 * Time.deltaTime,0, 0);
 

}

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

21 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

Related Questions

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

GuiTextures or OnGUI for android? 1 Answer

GUI.toggle and GUI.horizontalSlider to GUItextures. 0 Answers

GUI Texture disapears when I move it 1 Answer

can use two gui texture in scene 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