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 fullme7al · Sep 17, 2013 at 04:24 AM · touchcontrollerjumpguitexture

How to insert a touch guitexture into playercontrols

Hi everyone, thank you for taking a look at this and I hope you can help with this problem. I blended together a couple of character movement scripts and I created this third person mobile game one. Everything I have so far works fine(joystick,movement), but I'm having trouble replacing a pc jumpbutton with a touch guitexture. Here is what I have so far.

 [RequireComponent (typeof (Rigidbody))]
 [RequireComponent (typeof (CapsuleCollider))]
  
 public class CharacterControls : MonoBehaviour {
  
     public MPJoystick movejoystick;                //the jostick we use
     public Transform cameraTransform;    //this uses the camera position for movement
     public GUITexture jumpButton;  //this will be the jump button, it is not present in game yet
     public float speed = 8.0f;
     public float gravity = 6.0f;
     public float maxVelocityChange = 20.0f;
     public bool canJump = true;                    //can the character jump?
     public float jumpHeight = 2.0f;                //how high the character can jump
     private bool grounded = false;
      private Transform thisTransform;
  
  
     void Awake () {
         //thisTransform = (Transform)GetComponent(typeof(Transform)); 
         rigidbody.freezeRotation = true;
         rigidbody.useGravity = false;
     }
     void Update () {
         movement ();
 }
 public virtual void movement(){
         if (grounded) {
             // Calculate how fast we should be moving
             Vector3 targetVelocity = cameraTransform.TransformDirection(new Vector3(movejoystick.position.x,0,movejoystick.position.y));
             //Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             targetVelocity = transform.TransformDirection(targetVelocity);
             targetVelocity *= speed;
  
             Vector2 absJoyPos = new Vector2( Mathf.Abs( movejoystick.position.x ), 
                                      Mathf.Abs( movejoystick.position.y ) );
  targetVelocity *= speed * ( ( absJoyPos.x > absJoyPos.y ) ? absJoyPos.x : absJoyPos.y );
         
             // Apply a force that attempts to reach our target velocity
             Vector3 velocity = rigidbody.velocity;
             Vector3 velocityChange = (targetVelocity - velocity);
             velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
             velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
             velocityChange.y = 0;
             rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
  
             // Jump
             if (canJump && **Input.GetButton("Jump"))** //I'm unsure how to replace the input button here for a guitexture that would use touch and make it jump
             {
                 rigidbody.velocity = new Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
             }
         }
  
         // We apply gravity manually for more tuning control
         rigidbody.AddForce(new Vector3 (0, -gravity * rigidbody.mass, 0));
  
         grounded = false;
     }
  
     void OnCollisionStay () {
         grounded = true;    
     }
  
     float CalculateJumpVerticalSpeed () {
         // From the jump height and gravity we deduce the upwards speed 
         // for the character to reach at the apex.
         return Mathf.Sqrt(2 * jumpHeight * gravity);
     }
     
         
 
     
 }

I have a touch button script, but I'm unsure how to implement it.

 void Update () {
         touch ();
     }
     
 void touch(){
             if(Input.touchCount > 0 ){
  
                 for(int i = 0; i < Input.touchCount; i++){
 
                 Touch touch = Input.GetTouch(i);
                     if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)){
 
 //This space is where the action happens when you touch your custom GUI button on
 //your device.            
                 }    
                     if(touch.phase == TouchPhase.Ended && guiTexture.HitTest (touch.position)){
                         
                         //this stops the action
                     }
                 }
 
     }
 }
     
 }

Please, any and all help is welcome. I've done a lot of tutorials and for some reason I'm thinking I have to use getcomponent, but right now my brain is fried. I've tested the touch script with the camera background and it works for at least that. Thank you for taking your time to read this, and thanks in advance for any help.

Comment
Add comment · Show 3
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 fullme7al · Sep 19, 2013 at 12:42 AM 0
Share

Anyone? This will really help me out a lot. Thanks.

avatar image meat5000 ♦ · Sep 19, 2013 at 12:47 AM 0
Share

http://www.youtube.com/watch?v=z8XU$$anonymous$$-19kd$$anonymous$$

http://www.teotigraphix.org/2011/06/06/unity3d-detect-touch-on-guitexture/

Google is your friend (sounds evil)

avatar image fullme7al · Sep 19, 2013 at 12:54 AM 0
Share

I already tried the video you suggested. It disabled the joystick and my character couldn't move. The second site didn't have much. And i prefer Bing. :) Thanks though.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fullme7al · Sep 19, 2013 at 07:14 AM

I figured it out, and I feel great about it.

Comment
Add comment · Show 1 · 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 meat5000 ♦ · Sep 19, 2013 at 07:16 AM 0
Share

Good Job :)

Generally, if you know GUITexture is a part of GUILayer, you're ok

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

16 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

UFPS:ultimate fps cameraGUI texture wont show in game 0 Answers

Jumping and maintaining current velocity 1 Answer

Smoothing out jumping? 1 Answer

why does character controller accelerate off ledges? 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