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 /
avatar image
0
Question by Anonymous 1 · Sep 02, 2011 at 09:25 AM · androidiphoneguitexturecubehittest

conversion of script guitexture to cube or other primitive (iphone)

hello folks! i have this script

 function Update () {
     
  for (var touch : Touch in Input.touches)
  {
   if (guiTexture.HitTest (touch.position))
   {
     // we are now in the guitexture
     
     Application.LoadLevel(toLoad);
    } 

but i want to use something similar on a cube or sphere or such primitive so that i can detect touch on it, some help would be appreciated. Thank you

Comment
Add comment · Show 1
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 Anonymous 1 · Sep 02, 2011 at 09:26 AM 0
Share

if you din't got it , i am referring touch to iphone/android touch

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mohanrao164 · Sep 02, 2011 at 10:49 AM

In the standard assets the "DragRigidbody script" is there it will help u to detect the touch of the sphere or cube.

It is for the onmouseclick . A little changes have to make for iphone/andriod so it will work fine.

i have got the touch in my device.if any query let me come to know.

Comment
Add comment · Show 4 · 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 Anonymous 1 · Sep 02, 2011 at 12:59 PM 0
Share

i don't want touch to happen when camera moves , i want touch to happen strictly when i touch it on my android screen

avatar image mohanrao164 · Sep 03, 2011 at 05:13 AM 0
Share

will u be little clear so i can understand.u want wheather the object is touched or not or u want the object touch and moved.

avatar image Anonymous 1 · Sep 04, 2011 at 08:16 AM 0
Share

ok i just want something to happen when i touch the cube on my iphone/android

avatar image mohanrao164 · Sep 05, 2011 at 05:06 AM 0
Share

k i will give u the code in which i touched the sphere and drag anywhere in the scene or device. the file is in c# script. so i hope it would be helpful.

avatar image
0

Answer by mohanrao164 · Sep 05, 2011 at 05:22 AM

This code will help u and it is working for me.
using UnityEngine;
using System.Collections;

public class DragRigidbody : MonoBehaviour
{

 public float spring = 50.0f;
 public float damper = 5.0f;
 public float drag = 10.0f;
 public float angularDrag = 5.0f;
 public float distance = 0.2f;
 
 public  int nameOfConnectedBody;
 public  bool  attachToCenterOfMass = false;
 public  bool isOrbSelected;
 
 private  SpringJoint springJoint;
 private  Touch touch;
 public   string actname;

 
 void Update ()
 {
     
     if (Input.touchCount == 0) 
     {
         return;
     }

     Camera mainCamera = FindCamera ();
     RaycastHit hit = new RaycastHit ();
     transform.position = new Vector3 ( transform.position.x, 2.0f, transform.position.z );
     
 
     touch = Input.GetTouch (0);
     
     if (touch.phase == TouchPhase.Began) 
     {
         if(!Physics.SphereCast(mainCamera.ScreenPointToRay (touch.position),3.0f,out hit,300.0f))
         return;

         if (!hit.rigidbody || hit.rigidbody.isKinematic)
         return;
         if (!springJoint) 
         {
             GameObject go = new GameObject ("Rigidbody dragger");
             springJoint = (SpringJoint)go.AddComponent ("SpringJoint");
             go.rigidbody.isKinematic = true;
         }
         
         springJoint.transform.position = hit.point;
         
         if (attachToCenterOfMass) 
         {
             Vector3 anchor = transform.TransformDirection (hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
             anchor = springJoint.transform.InverseTransformPoint (anchor);
             springJoint.anchor = anchor;
         } 
         else 
         {
             springJoint.anchor = Vector3.zero;
         }
         
         springJoint.spring = spring;
         springJoint.damper = damper;
         springJoint.maxDistance = distance;
         springJoint.connectedBody = hit.rigidbody;
             
         StartCoroutine ("DragObject", hit.distance);
         isOrbSelected = true;
     }
 }
 

 IEnumerator DragObject (float distance)
 {
     if (touch.phase == TouchPhase.Began)
     {
         float oldDrag = springJoint.connectedBody.drag;
         float oldAngularDrag = springJoint.connectedBody.angularDrag;
         springJoint.connectedBody.drag = drag;
         springJoint.connectedBody.angularDrag = angularDrag;
         Camera mainCamera = FindCamera ();
         
         while (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
         {
             transform.position = new Vector3 ( transform.position.x, 2.0f, transform.position.z );
             nameOfConnectedBody =  springJoint.connectedBody.gameObject.GetInstanceID();
             actname = springJoint.connectedBody.gameObject.name;
             Ray ray = mainCamera.ScreenPointToRay (touch.position);
             springJoint.transform.position = ray.GetPoint (distance);
             yield return 0;
         }
         
         if (springJoint.connectedBody) 
         {
             springJoint.connectedBody.drag = oldDrag;
             springJoint.connectedBody.angularDrag = oldAngularDrag;
             springJoint.connectedBody = null;
         }
     
         isOrbSelected = false;
         nameOfConnectedBody = 0;
         actname="";
         
         
     }
     
 }

 Camera FindCamera ()
 {
     if (camera)
         return camera;
     else
         return Camera.main;
 }

}

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

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

2 People are following this question.

avatar image avatar image

Related Questions

[Question Duplicated] conversion of script guitexture to cube or other primitive (iphone) 0 Answers

HUD on Android/iPhone : GUITexture or OnGUI (drawTexture) ? 2 Answers

Strange collision problem with block and terrain 1 Answer

use HitTest to check if a screen area is touched 1 Answer

Detecting Touch on Iphone and Android 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