FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionDrag script

more_horiz
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

descriptionRe: Drag script

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

descriptionRe: Drag script

more_horiz
[You must be registered and logged in to see this link.] 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

descriptionRe: Drag script

more_horiz
it doesn't work for me No

descriptionRe: Drag script

more_horiz
[You must be registered and logged in to see this link.] wrote:
it doesn't work for me No

Why? But you also can use the Drag Rigidbody present in Unity

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

descriptionRe: Drag script

more_horiz
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] 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?

_________________
-BryceCain25

descriptionRe: Drag script

more_horiz
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] 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

_________________
-BryceCain25

descriptionRe: Drag script

more_horiz
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] 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

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

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