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
Share
Go down
avatar
Moderator
Moderator
Posts : 329
Points : 2176
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Drag script

on Sat May 31, 2014 2:31 am
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
avatar
Admin
Admin
Posts : 608
Points : 3169
Rep : 406
Join date : 2013-12-11
Age : 21
View user profilehttps://www.youtube.com/user/misterninjaboy

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!
avatar
Moderator
Moderator
Posts : 329
Points : 2176
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Drag script

on Mon Jun 02, 2014 11:51 am
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
Member [Lv. 1]
Member [Lv. 1]
Posts : 2
Points : 1575
Rep : 0
Join date : 2014-03-31
View user profile

Re: Drag script

on Tue Sep 02, 2014 1:47 pm
it doesn't work for me No
avatar
Moderator
Moderator
Posts : 329
Points : 2176
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Drag script

on Wed Sep 03, 2014 3:09 am
Mohammed-Mrx wrote:it doesn't work for me No
Why? But you also can use the Drag Rigidbody present in Unity
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2141
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

Re: Drag script

on Thu Sep 11, 2014 11:27 pm
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?
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2141
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

Re: Drag script

on Thu Sep 11, 2014 11:28 pm
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
avatar
Moderator
Moderator
Posts : 329
Points : 2176
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Drag script

on Fri Sep 12, 2014 6:03 am
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
Back to top
Permissions in this forum:
You cannot reply to topics in this forum