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 Earth-O-Matic · Apr 17, 2011 at 05:47 AM · iphonetouchdragclick

Click Drag not working on iphone

Hey again all. I have a click drag script here that runs fine otherwise and doesn't produce errors but once I get the game on my iphone it just doesn't work. Any one have an idea why? Here's the code.

C#....

using UnityEngine; using System.Collections;

[RequireComponent(typeof(MeshCollider))]

public class clickDragMesh : MonoBehaviour {

private Vector3 screenPoint; private Vector3 offset;

void OnMouseDown() { screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);

offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));

}

void OnMouseDrag() { Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);

Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; transform.position = curPosition;

}

}

As always, thank you for the help!

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

2 Replies

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

Answer by Mortennobel · Apr 17, 2011 at 08:09 AM

You cannot use mouse controls on your iPhone, but has to use touch events instead. The touch events can be read from the Input class.

http://unity3d.com/support/documentation/ScriptReference/Input-touches.html

This means that you have to code the "mouse drag" functionality yourself.

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 Earth-O-Matic · Apr 18, 2011 at 02:39 AM 0
Share

I redid the code and now I can click and drag.

avatar image
0

Answer by Earth-O-Matic · Apr 18, 2011 at 02:41 AM

Here is the code if anyone is interested. I'm still having trouble with stopping the drag and doping the object when I lift my finger. This is just the drag code I used. I'm using a modified version of this code currently to touch and drop - no drag. Would like drag though if I can figure it out or someone else can chime in.

#pragma strict

var cam : Camera; var hit : RaycastHit;

function Start() { cam = Camera.main; }

function Update () { if(iPhoneInput.touchCount == 1) { var touchPos : Vector2 = iPhoneInput.touches[0].position; var ray : Ray = cam.ScreenPointToRay(touchPos);

     if(Physics.Raycast(ray,hit,100))
     {

         transform.position = cam.ScreenToWorldPoint(Vector3(touchPos.x,touchPos.y,10));
     }
 }

}

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

No one has followed this question yet.

Related Questions

How do i make a continuos touch that triggers more then one "button"? 1 Answer

Touch and drag an object 0 Answers

Destroy on touch for iphone 1 Answer

Detect screen tap vs. drag 2 Answers

What's the matter with this script? Detect object dragging with iPhone Touch 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