Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Drag script

Drag script

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Drag script on Sat May 31, 2014 2:31 am

developer23


Moderator
Moderator
is a script that allows you to drag the object by holding down the right mouse button
Code:
#pragma strict
private var ray : Ray;
private var hit : RaycastHit;

function Start () {

}

function Update () {
   if(Input.GetMouseButton(0)){
      ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      if(Physics.Raycast(ray, hit)){
         transform.position.x = hit.point.x;
         transform.position.y = hit.point.y;
      }
   }

}



Last edited by developer23 on Mon Jun 02, 2014 11:51 am; edited 1 time in total

View user profile http://masterdevelopers.altervista.org/

2 Re: Drag script on Mon Jun 02, 2014 4:08 am

Can you just include a breif little description on what exactly the script does? It will save alot of time for people. Thanks!

View user profile http://www.youtube.com/user/misterninjaboy

3 Re: Drag script on Mon Jun 02, 2014 11:51 am

developer23


Moderator
Moderator
MisterNinjaBoy wrote:Can you just include a breif little description on what exactly the script does? It will save alot of time for people. Thanks!
Ok,added in description Wink

View user profile http://masterdevelopers.altervista.org/

4 Re: Drag script on Tue Sep 02, 2014 1:47 pm

Mohammed-Mrx


Member [Lv. 1]
Member [Lv. 1]
it doesn't work for me No

View user profile

5 Re: Drag script on Wed Sep 03, 2014 3:09 am

developer23


Moderator
Moderator
Mohammed-Mrx wrote:it doesn't work for me No
Why? But you also can use the Drag Rigidbody present in Unity

View user profile http://masterdevelopers.altervista.org/

6 Re: Drag script on Thu Sep 11, 2014 11:27 pm

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
developer23 wrote:
Mohammed-Mrx wrote:it doesn't work for me No
Why? But you also can use the Drag Rigidbody present in Unity
Exactly, make sure you add a rigidbody and it's not kinematic. Please note, this script (developer23's) will do the dragging when you left click on the actual object, In this case I am pretty sure you have to make a trigger right?

View user profile

7 Re: Drag script on Thu Sep 11, 2014 11:28 pm

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
BryceCain25 wrote:
developer23 wrote:
Mohammed-Mrx wrote:it doesn't work for me No
Why? But you also can use the Drag Rigidbody present in Unity
Exactly, make sure you add a rigidbody and it's not kinematic. Please note, this script (developer23's) will do the dragging when you left click on the actual object, In this case I am pretty sure you have to make a trigger right?
Edit: no trigger is needed

View user profile

8 Re: Drag script on Fri Sep 12, 2014 6:03 am

developer23


Moderator
Moderator
BryceCain25 wrote:
BryceCain25 wrote:
developer23 wrote:
Mohammed-Mrx wrote:it doesn't work for me No
Why? But you also can use the Drag Rigidbody present in Unity
Exactly, make sure you add a rigidbody and it's not kinematic. Please note, this script (developer23's) will do the dragging when you left click on the actual object, In this case I am pretty sure you have to make a trigger right?
Edit: no trigger is needed
Yeah,no trigger is needed Smile

View user profile http://masterdevelopers.altervista.org/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum